Class: ActiveScaffold::DataStructures::NestedInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/active_scaffold/data_structures/nested_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#associationObject

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_associationObject

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_fieldsObject

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_idObject

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_modelObject

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_scaffoldObject

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

Returns:

  • (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_sortingObject



56
57
58
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 56

def default_sorting
  association[:order]
end

#habtm?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


48
49
50
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 48

def has_one?
  association[:type] == :one_to_one
end

#nameObject



36
37
38
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 36

def name
  association[:name]
end

#parent_scopeObject



32
33
34
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 32

def parent_scope
  parent_model[parent_id]
end

#sorted?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 52

def sorted?
  association.has_key? :order
end

#to_paramsObject



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