Class: DynamicFields::Index
- Inherits:
-
Object
- Object
- DynamicFields::Index
- Defined in:
- lib/dynamic_fields/index.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(field_or_fields, options = {}) ⇒ Index
constructor
A new instance of Index.
- #migration_string_for(table_state, action) ⇒ Object
- #to_s ⇒ Object
- #unique? ⇒ Boolean
Constructor Details
#initialize(field_or_fields, options = {}) ⇒ Index
Returns a new instance of Index.
5 6 7 8 9 10 |
# File 'lib/dynamic_fields/index.rb', line 5 def initialize field_or_fields, ={} @fields = field_or_fields @name = [:name] @unique = .delete(:unique) == true @options = end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
3 4 5 |
# File 'lib/dynamic_fields/index.rb', line 3 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/dynamic_fields/index.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/dynamic_fields/index.rb', line 3 def @options end |
Instance Method Details
#id ⇒ Object
12 13 14 |
# File 'lib/dynamic_fields/index.rb', line 12 def id name end |
#migration_string_for(table_state, action) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dynamic_fields/index.rb', line 24 def migration_string_for table_state, action args = [] case action = action.to_sym when :add args << (fields.is_a?(Array) ? fields : fields.to_sym).inspect args << ":name => #{to_s.inspect}" args << ":unique => true" if unique? when :remove args << ":name => #{to_s.inspect}" end args.join(', ').gsub('\\', '') end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/dynamic_fields/index.rb', line 16 def to_s name.to_s end |
#unique? ⇒ Boolean
20 21 22 |
# File 'lib/dynamic_fields/index.rb', line 20 def unique? @unique == true end |