Class: RailsClafer::ClaferElement
- Inherits:
-
Object
- Object
- RailsClafer::ClaferElement
- Defined in:
- lib/rails_clafer/clafer_element.rb
Instance Attribute Summary collapse
-
#card ⇒ Object
Returns the value of attribute card.
-
#constraint ⇒ Object
Returns the value of attribute constraint.
-
#gcard ⇒ Object
Returns the value of attribute gcard.
-
#is_abstract ⇒ Object
(also: #is_abstract?)
Returns the value of attribute is_abstract.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .calc_abstract_clafer_list ⇒ Object
- .dfs(assoc_map, class_name, path, target, abs_model_map) ⇒ Object
- .from_rails_models(rails_models) ⇒ Object
- .model_belong_to_mult_models?(class_name) ⇒ Boolean
Instance Method Summary collapse
- #children ⇒ Object
-
#initialize(name, ruby_class, is_abstract) ⇒ ClaferElement
constructor
A new instance of ClaferElement.
Constructor Details
#initialize(name, ruby_class, is_abstract) ⇒ ClaferElement
Returns a new instance of ClaferElement.
62 63 64 65 66 67 68 69 |
# File 'lib/rails_clafer/clafer_element.rb', line 62 def initialize(name, ruby_class, is_abstract) @is_abstract = is_abstract @name = ClaferModel.claferize_name name @klass = ruby_class @gcard = GCard.new @card = Card.new @constraint = "" end |
Instance Attribute Details
#card ⇒ Object
Returns the value of attribute card.
61 62 63 |
# File 'lib/rails_clafer/clafer_element.rb', line 61 def card @card end |
#constraint ⇒ Object
Returns the value of attribute constraint.
61 62 63 |
# File 'lib/rails_clafer/clafer_element.rb', line 61 def constraint @constraint end |
#gcard ⇒ Object
Returns the value of attribute gcard.
61 62 63 |
# File 'lib/rails_clafer/clafer_element.rb', line 61 def gcard @gcard end |
#is_abstract ⇒ Object Also known as: is_abstract?
Returns the value of attribute is_abstract.
59 60 61 |
# File 'lib/rails_clafer/clafer_element.rb', line 59 def is_abstract @is_abstract end |
#name ⇒ Object
Returns the value of attribute name.
61 62 63 |
# File 'lib/rails_clafer/clafer_element.rb', line 61 def name @name end |
Class Method Details
.calc_abstract_clafer_list ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rails_clafer/clafer_element.rb', line 30 def calc_abstract_clafer_list() abs_model_map = Hash[ClaferModel.rails_models.collect {|klass| [ClaferModel.claferize_name(klass.name), false] }] #first pass to check if ruby model belongs to more than one model abs_model_map.each do |class_name, is_abstract| if model_belong_to_mult_models? class_name abs_model_map[class_name] = true end end # second pass to look for circular associations abs_model_map.each do |class_name, is_abstract| if !is_abstract dfs(ClaferModel.assoc_src, class_name, {class_name => true}, class_name, abs_model_map ) end end abs_model_map end |
.dfs(assoc_map, class_name, path, target, abs_model_map) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_clafer/clafer_element.rb', line 16 def dfs (assoc_map, class_name, path, target, abs_model_map) if assoc_map.has_key? class_name assoc_map[class_name].each do |assoc| if assoc.dst == target abs_model_map.merge! path else if !path.has_key? assoc.dst dfs(assoc_map, assoc.dst, path.merge({assoc.dst => true}), target, abs_model_map) end end end end end |
.from_rails_models(rails_models) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/rails_clafer/clafer_element.rb', line 47 def from_rails_models(rails_models) # create clafer for each metaclafer and assoc dst if not already exists class_mapping = Hash[rails_models.collect {|model_class| [ ClaferModel.claferize_name(model_class.name), model_class] }] abs_model_map = calc_abstract_clafer_list class_mapping.collect do |name, klass| new name, klass, abs_model_map[name] end end |
.model_belong_to_mult_models?(class_name) ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rails_clafer/clafer_element.rb', line 4 def model_belong_to_mult_models?(class_name) if ClaferModel.assoc_dst.has_key? class_name if ClaferModel.assoc_dst[class_name].size>1 true else false end else true end end |
Instance Method Details
#children ⇒ Object
71 72 73 |
# File 'lib/rails_clafer/clafer_element.rb', line 71 def children @children ||= children_list end |