Class: CMS::Attribute
- Inherits:
-
Object
- Object
- CMS::Attribute
- Defined in:
- lib/cms/attribute.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #field_name ⇒ Object
- #file? ⇒ Boolean
- #form_type ⇒ Object
- #has_index? ⇒ Boolean
- #has_uniq_index? ⇒ Boolean
- #index_name ⇒ Object
-
#initialize(name, format, options) ⇒ Attribute
constructor
A new instance of Attribute.
- #inject_index_options ⇒ Object
- #inject_options ⇒ Object
- #migration_type ⇒ Object
- #orderable? ⇒ Boolean
- #reference? ⇒ Boolean
- #reference_to ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, format, options) ⇒ Attribute
Returns a new instance of Attribute.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/cms/attribute.rb', line 4 def initialize name, format, @name = name @format = format @options = @attr_options = if self.format.boolean? { null: false, default: false } else {} end end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
2 3 4 |
# File 'lib/cms/attribute.rb', line 2 def format @format end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/cms/attribute.rb', line 2 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
2 3 4 |
# File 'lib/cms/attribute.rb', line 2 def @options end |
Instance Method Details
#field_name ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/cms/attribute.rb', line 66 def field_name if reference? name + '_id' else name end end |
#file? ⇒ Boolean
24 |
# File 'lib/cms/attribute.rb', line 24 def file? ; format.file? end |
#form_type ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cms/attribute.rb', line 52 def form_type if format.orderable? || format.reference? 'select' elsif format.text? or format.html? 'text_area' elsif format.file? 'file_field' elsif format.boolean? 'check_box' else 'text_field' end end |
#has_index? ⇒ Boolean
26 27 28 |
# File 'lib/cms/attribute.rb', line 26 def has_index? false end |
#has_uniq_index? ⇒ Boolean
30 31 32 |
# File 'lib/cms/attribute.rb', line 30 def has_uniq_index? false end |
#index_name ⇒ Object
34 35 36 |
# File 'lib/cms/attribute.rb', line 34 def index_name format.reference? ? "#{name}_id" : name end |
#inject_index_options ⇒ Object
78 79 80 |
# File 'lib/cms/attribute.rb', line 78 def has_uniq_index? ? ", :unique => true" : '' end |
#inject_options ⇒ Object
74 75 76 |
# File 'lib/cms/attribute.rb', line 74 def CMS::Template.(@attr_options) end |
#migration_type ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cms/attribute.rb', line 38 def migration_type if format.reference? 'belongs_to' elsif format.orderable? 'integer' elsif format.file? 'string' elsif format.html? 'text' else format end end |
#orderable? ⇒ Boolean
23 |
# File 'lib/cms/attribute.rb', line 23 def orderable? ; format.orderable? end |
#reference? ⇒ Boolean
22 |
# File 'lib/cms/attribute.rb', line 22 def reference? ; format.reference? end |
#reference_to ⇒ Object
82 83 84 85 86 |
# File 'lib/cms/attribute.rb', line 82 def reference_to if reference? @reference_to ||= CMS::Configuration.types.find{ |t| t.name == @options['reference_to'] } end end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/cms/attribute.rb', line 88 def to_s name end |