Module: DirModel::Model::Relations
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/dir_model/model/relations.rb
Instance Method Summary collapse
-
#append_dir_model(source_path, options = {}) ⇒ Model
Appends model to the parent and returns it.
-
#append_dir_models(source_path, options = {}) ⇒ Model
Appends modeld to the parent and returns it.
-
#child? ⇒ Boolean
Returns true, if the instance is a child.
- #has_many? ⇒ Boolean
- #has_one? ⇒ Boolean
- #has_relations? ⇒ Boolean
Instance Method Details
#append_dir_model(source_path, options = {}) ⇒ Model
Appends model to the parent and returns it
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dir_model/model/relations.rb', line 22 def append_dir_model(source_path, ={}) relation_name = [:relation_name] = [:relation_options] = [:dir_model_class] foreign_key = [:foreign_key] foreign_value = self.send(foreign_key) = .new(source_path, .reverse_merge(parent: self, foreign_value: foreign_value)) return unless unless .skip? if public_send(relation_name).present? raise StandardError.new("There are more of one #{relation_name} => #{related_class} for #{self.class.name}") end public_send("#{relation_name}=", ) else nil end end |
#append_dir_models(source_path, options = {}) ⇒ Model
Appends modeld to the parent and returns it
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dir_model/model/relations.rb', line 48 def append_dir_models(source_path, ={}) relation_name = self.class.has_many_relationship.keys.first = self.class.has_many_relationship.values.first = [:dir_model_class] foreign_key = [:foreign_key] foreign_value = self.send(foreign_key) = .new(source_path, .reverse_merge(parent: self, foreign_value: foreign_value)) return unless unless .skip? public_send(relation_name) << else nil end end |
#child? ⇒ Boolean
Returns true, if the instance is a child
11 12 13 |
# File 'lib/dir_model/model/relations.rb', line 11 def child? !!parent end |
#has_many? ⇒ Boolean
72 73 74 |
# File 'lib/dir_model/model/relations.rb', line 72 def has_many? false end |
#has_one? ⇒ Boolean
68 69 70 |
# File 'lib/dir_model/model/relations.rb', line 68 def has_one? false end |
#has_relations? ⇒ Boolean
15 16 17 |
# File 'lib/dir_model/model/relations.rb', line 15 def has_relations? has_one? || has_many? end |