Class: Lolita::Configuration::EditableList
- Inherits:
-
Object
- Object
- Lolita::Configuration::EditableList
- Defined in:
- lib/lolita-editable-list/configuration/editable_list.rb
Overview
Example
# all supported columns become editable
lolita do
list do
is_editable
end
end
# only some
lolita do
list do
is_editable :only => [:name,:title]
end
end
lolita do
list do
is_editable :except => [:name]
end
end
# or as block
lolita do
list do
is_editable do
only :name, :title
end
end
end
Constant Summary collapse
- SUPPORTED_TYPES =
[:integer,:string,:decimal]
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Instance Method Summary collapse
- #columns ⇒ Object
- #except(*args) ⇒ Object
-
#initialize(list, *args, &block) ⇒ EditableList
constructor
A new instance of EditableList.
- #only(*args) ⇒ Object
-
#set_attributes(*args) ⇒ Object
Used to set attributes if block not given.
Constructor Details
#initialize(list, *args, &block) ⇒ EditableList
Returns a new instance of EditableList.
38 39 40 41 42 43 44 |
# File 'lib/lolita-editable-list/configuration/editable_list.rb', line 38 def initialize(list,*args,&block) self.list = list self.all_column_names = extract_supported_columns list.columns.map(&:name).map(&:to_sym) self.set_attributes(*args) self.instance_eval(&block) if block_given? validate end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
34 35 36 |
# File 'lib/lolita-editable-list/configuration/editable_list.rb', line 34 def list @list end |
Instance Method Details
#columns ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lolita-editable-list/configuration/editable_list.rb', line 56 def columns if self.only self.only.select{|name| self.all_column_names.include?(name)} else if self.except self.all_column_names.select{|name| !self.except.include?(name)} else self.all_column_names end end end |
#except(*args) ⇒ Object
46 47 48 49 |
# File 'lib/lolita-editable-list/configuration/editable_list.rb', line 46 def except *args @except = args unless args.empty? @except end |
#only(*args) ⇒ Object
51 52 53 54 |
# File 'lib/lolita-editable-list/configuration/editable_list.rb', line 51 def only *args @only = args unless args.empty? @only end |
#set_attributes(*args) ⇒ Object
Used to set attributes if block not given.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/lolita-editable-list/configuration/editable_list.rb', line 69 def set_attributes(*args) if args && args[0] if args[0].is_a?(Hash) args[0].each{|m,value| self.send("#{m}=".to_sym,value) } else raise ArgumentError.new("Lolita::Configuration::List::Editable arguments must be Hash instead of #{args[0].class}") end end end |