Skip to content

Commit

Permalink
Merge pull request maxdemarzi#78 from blizkreeg/models
Browse files Browse the repository at this point in the history
change composed_attributes to track attribute with type and index
  • Loading branch information
blizkreeg committed Dec 18, 2013
2 parents 149b2b2 + cbbca30 commit 5f04657
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
3 changes: 0 additions & 3 deletions lib/config/graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/deja/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/deja/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/deja/schema_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/deja/type_caster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down

0 comments on commit 5f04657

Please sign in to comment.