Class: SelectableAttrRails::Helpers::AbstractSelectionBuilder
- Inherits:
-
Object
- Object
- SelectableAttrRails::Helpers::AbstractSelectionBuilder
show all
- Defined in:
- lib/selectable_attr_rails/helpers/abstract_selection_helper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(object, object_name, method, options, template) ⇒ AbstractSelectionBuilder
Returns a new instance of AbstractSelectionBuilder.
5
6
7
8
9
10
11
12
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 5
def initialize(object, object_name, method, options, template)
@object, @object_name, @method = object, object_name, method
@base_name = @object.class.enum_base_name(method.to_s)
@template = template
@entry_hash = nil
@options = options || {}
@entry_hash_array = @options[:entry_hash_array]
end
|
Instance Attribute Details
#entry_hash ⇒ Object
Returns the value of attribute entry_hash.
3
4
5
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 3
def entry_hash
@entry_hash
end
|
Instance Method Details
#add_class_name(options, class_name) ⇒ Object
30
31
32
33
34
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 30
def add_class_name(options, class_name)
(options ||= {}).stringify_keys!
(options['class'] ||= '') << ' ' << class_name
options
end
|
#camelize_keys(hash, first_letter = :lower) ⇒ Object
36
37
38
39
40
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 36
def camelize_keys(hash, first_letter = :lower)
result = {}
hash.each{|key, value|result[key.to_s.camelize(first_letter)] = value}
result
end
|
#enum_hash_array_from_class ⇒ Object
19
20
21
22
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 19
def enum_hash_array_from_class
base_name = @object.class.enum_base_name(@method.to_s)
@object.class.send("#{base_name}_hash_array")
end
|
#enum_hash_array_from_object ⇒ Object
14
15
16
17
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 14
def enum_hash_array_from_object
base_name = @object.class.enum_base_name(@method.to_s)
@object.send("#{base_name}_hash_array")
end
|
#tag_id(tag) ⇒ Object
24
25
26
27
28
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 24
def tag_id(tag)
result = nil
tag.scan(/ id\=\"(.*?)\"/){|s|result = s}
return result
end
|
#update_options(dest, *options_array) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/selectable_attr_rails/helpers/abstract_selection_helper.rb', line 42
def update_options(dest, *options_array)
result = dest || {}
options_array.each do |options|
next unless options
if class_name = options.delete(:class)
add_class_name(result, class_name)
end
result.update(options)
end
result
end
|