Class: ActiveScaffold::DataStructures::NestedInfo
- Inherits:
-
Object
- Object
- ActiveScaffold::DataStructures::NestedInfo
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.
28
29
30
31
32
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 28
def initialize(model, nested_info)
@parent_model = nested_info[:parent_model]
@parent_id = nested_info[:parent_id]
@parent_scaffold = nested_info[:parent_scaffold]
end
|
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
26
27
28
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 26
def association
@association
end
|
#child_association ⇒ Object
Returns the value of attribute child_association.
26
27
28
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 26
def child_association
@child_association
end
|
#constrained_fields ⇒ Object
Returns the value of attribute constrained_fields.
26
27
28
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 26
def constrained_fields
@constrained_fields
end
|
#parent_id ⇒ Object
Returns the value of attribute parent_id.
26
27
28
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 26
def parent_id
@parent_id
end
|
#parent_model ⇒ Object
Returns the value of attribute parent_model.
26
27
28
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 26
def parent_model
@parent_model
end
|
#parent_scaffold ⇒ Object
Returns the value of attribute parent_scaffold.
26
27
28
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 26
def parent_scaffold
@parent_scaffold
end
|
Returns the value of attribute scope.
26
27
28
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 26
def scope
@scope
end
|
Class Method Details
.get(model, params) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 3
def self.get(model, params)
nested_info = {}
begin
nested_info[:name] = (params[:association] || params[:named_scope]).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] = if params[:association].nil?
params[nested_info[:parent_model].name.foreign_key]
else
params[nested_info[:parent_model].reflect_on_association(params[:association].to_sym).active_record.name.foreign_key]
end
if nested_info[:parent_id]
unless params[:association].nil?
ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info)
else
ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info)
end
end
rescue ActiveScaffold::ControllerNotFound
nil
end
end
|
Instance Method Details
#belongs_to? ⇒ Boolean
56
57
58
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 56
def belongs_to?
false
end
|
#habtm? ⇒ Boolean
48
49
50
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 48
def habtm?
false
end
|
#has_many? ⇒ Boolean
52
53
54
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 52
def has_many?
false
end
|
#has_one? ⇒ Boolean
60
61
62
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 60
def has_one?
false
end
|
#new_instance? ⇒ Boolean
38
39
40
41
42
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 38
def new_instance?
result = @new_instance.nil?
@new_instance = false
result
end
|
#parent_scope ⇒ Object
44
45
46
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 44
def parent_scope
@parent_scope ||= parent_model.find(parent_id)
end
|
#plural_association? ⇒ Boolean
68
69
70
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 68
def plural_association?
has_many? || habtm?
end
|
#readonly? ⇒ Boolean
76
77
78
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 76
def readonly?
false
end
|
#singular_association? ⇒ Boolean
64
65
66
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 64
def singular_association?
belongs_to? || has_one?
end
|
#sorted? ⇒ Boolean
80
81
82
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 80
def sorted?
false
end
|
#through_association? ⇒ Boolean
72
73
74
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 72
def through_association?
false
end
|
#to_params ⇒ Object
34
35
36
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 34
def to_params
{:parent_scaffold => parent_scaffold.controller_path}
end
|