Class: ActiveScaffold::DataStructures::NestedInfo
- Defined in:
- lib/active_scaffold/data_structures/nested_info.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
-
#child_association ⇒ Object
Returns the value of attribute child_association.
-
#constrained_fields ⇒ Object
Returns the value of attribute constrained_fields.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#parent_model ⇒ Object
Returns the value of attribute parent_model.
-
#parent_scaffold ⇒ Object
Returns the value of attribute parent_scaffold.
Class Method Summary collapse
Instance Method Summary collapse
- #belongs_to? ⇒ Boolean
- #default_sorting ⇒ Object
- #habtm? ⇒ Boolean
- #has_one? ⇒ Boolean
-
#initialize(model, nested_info) ⇒ NestedInfo
constructor
A new instance of NestedInfo.
- #name ⇒ Object
- #parent_scope ⇒ Object
- #sorted? ⇒ Boolean
- #to_params ⇒ Object
Constructor Details
#initialize(model, nested_info) ⇒ NestedInfo
Returns a new instance of NestedInfo.
20 21 22 23 24 25 26 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 20 def initialize(model, nested_info) @parent_model = nested_info[:parent_model] @parent_id = nested_info[:parent_id] @parent_scaffold = nested_info[:parent_scaffold] @association = @parent_model.association_reflection(nested_info[:name]) iterate_model_associations(model) end |
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
18 19 20 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 18 def association @association end |
#child_association ⇒ Object
Returns the value of attribute child_association.
18 19 20 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 18 def child_association @child_association end |
#constrained_fields ⇒ Object
Returns the value of attribute constrained_fields.
18 19 20 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 18 def constrained_fields @constrained_fields end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
18 19 20 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 18 def parent_id @parent_id end |
#parent_model ⇒ Object
Returns the value of attribute parent_model.
18 19 20 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 18 def parent_model @parent_model end |
#parent_scaffold ⇒ Object
Returns the value of attribute parent_scaffold.
18 19 20 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 18 def parent_scaffold @parent_scaffold end |
Class Method Details
.get(model, params) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 3 def self.get(model, params) nested_info = {} begin nested_info[:name] = params[:association].to_sym nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key] if nested_info[:parent_id] ActiveScaffold::DataStructures::NestedInfo.new(model, nested_info) end rescue ActiveScaffold::ControllerNotFound nil end end |
Instance Method Details
#belongs_to? ⇒ Boolean
44 45 46 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 44 def belongs_to? association[:type] == :many_to_one end |
#default_sorting ⇒ Object
56 57 58 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 56 def default_sorting association[:order] end |
#habtm? ⇒ Boolean
40 41 42 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 40 def habtm? association[:type] == :many_to_many end |
#has_one? ⇒ Boolean
48 49 50 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 48 def has_one? association[:type] == :one_to_one end |
#name ⇒ Object
36 37 38 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 36 def name association[:name] end |
#parent_scope ⇒ Object
32 33 34 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 32 def parent_scope parent_model[parent_id] end |
#sorted? ⇒ Boolean
52 53 54 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 52 def sorted? association.has_key? :order end |
#to_params ⇒ Object
28 29 30 |
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 28 def to_params {:parent_scaffold => parent_scaffold.controller_path, :association => association[:name], :assoc_id => parent_id} end |