From cbbca30ce473079a34312493fc05f75f142d3c3d Mon Sep 17 00:00:00 2001 From: Vineet Thanedar Date: Wed, 18 Dec 2013 14:06:15 -0800 Subject: [PATCH] change composed_attributes to track attribute with type and index --- lib/config/graph.yml | 3 --- lib/deja/model.rb | 2 +- lib/deja/node.rb | 2 +- lib/deja/schema_generator.rb | 6 +++--- lib/deja/type_caster.rb | 4 ++-- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/config/graph.yml b/lib/config/graph.yml index d957b90..d2c197c 100644 --- a/lib/config/graph.yml +++ b/lib/config/graph.yml @@ -20,7 +20,6 @@ staging: gremlin_path: "/ext/GremlinPlugin/graphdb/execute_script" log_file: "neography.log" log_enabled: false - slow_log_threshold: 0 # time in ms for query logging max_threads: 20 authentication: nil # 'basic' or 'digest' username: nil @@ -34,7 +33,6 @@ test: gremlin_path: "/ext/GremlinPlugin/graphdb/execute_script" log_file: "neography.log" log_enabled: false - slow_log_threshold: 0 # time in ms for query logging max_threads: 20 authentication: nil # 'basic' or 'digest' username: nil @@ -48,7 +46,6 @@ production: gremlin_path: "/ext/GremlinPlugin/graphdb/execute_script" log_file: "neography.log" log_enabled: false - slow_log_threshold: 0 # time in ms for query logging max_threads: 20 authentication: nil # 'basic' or 'digest' username: nil diff --git a/lib/deja/model.rb b/lib/deja/model.rb index 54ec4c1..5e650f4 100644 --- a/lib/deja/model.rb +++ b/lib/deja/model.rb @@ -28,7 +28,7 @@ def initialize(*args) run_callbacks :initialize do @id = nil options = args.extract_options! - options = options.select { |k, v| self.class.attributes.include?(k) || self.class.composed_attributes.include?(k)} + options = options.select { |k, v| self.class.attributes.include?(k) || self.class.composed_attributes.keys.include?(k)} super(options) yield(args) if block_given? end diff --git a/lib/deja/node.rb b/lib/deja/node.rb index 78956f3..efcd3e2 100644 --- a/lib/deja/node.rb +++ b/lib/deja/node.rb @@ -214,7 +214,7 @@ def destroy def persisted_attributes inst_vars = instance_variables.map { |i| i.to_s[1..-1].to_sym } - attrs = (self.class.attributes + self.class.composed_attributes) & inst_vars + attrs = (self.class.attributes + self.class.composed_attributes.keys) & inst_vars attrs.inject({}) do |memo, (k, v)| memo[k] = TypeCaster.typecast(k, send(k), self.class.name) memo diff --git a/lib/deja/schema_generator.rb b/lib/deja/schema_generator.rb index d7e4cbb..37bc087 100644 --- a/lib/deja/schema_generator.rb +++ b/lib/deja/schema_generator.rb @@ -52,11 +52,11 @@ def indexes end def composed_attributes(attrs = nil) - @@composed_attributes[self.name] ||= [] + @@composed_attributes[self.name] ||= {} if attrs - @@composed_attributes[self.name] += attrs - @@composed_attributes[self.name].uniq! + @@composed_attributes[self.name].merge!(attrs) + # @@composed_attributes[self.name].uniq! else @@composed_attributes[self.name] end diff --git a/lib/deja/type_caster.rb b/lib/deja/type_caster.rb index 3614dbd..6969dd3 100644 --- a/lib/deja/type_caster.rb +++ b/lib/deja/type_caster.rb @@ -6,7 +6,7 @@ module TypeCaster def self.reversecast(attr_name, value, klass) return nil if value.nil? - data_type = klass.constantize.schema[:attributes][attr_name][:type].to_s + data_type = (klass.constantize.schema[:attributes][attr_name] || klass.constantize.composed_attributes[attr_name])[:type].to_s case data_type when 'Integer' @@ -30,7 +30,7 @@ def self.reversecast(attr_name, value, klass) def self.typecast(attr_name, value, klass) return nil if value.nil? - data_type = klass.constantize.schema[:attributes][attr_name][:type].to_s + data_type = (klass.constantize.schema[:attributes][attr_name] || klass.constantize.composed_attributes[attr_name])[:type].to_s case data_type when 'Integer'