Class: Rails::Generators::GeneratedAttribute
- Inherits:
-
Object
- Object
- Rails::Generators::GeneratedAttribute
- Defined in:
- lib/rails/generators/sequel/generated_attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #alter_definition ⇒ Object
- #create_definition ⇒ Object
- #default ⇒ Object
- #field_type ⇒ Object
- #human_name ⇒ Object
-
#initialize(name, type) ⇒ GeneratedAttribute
constructor
A new instance of GeneratedAttribute.
- #reference? ⇒ Boolean
Constructor Details
#initialize(name, type) ⇒ GeneratedAttribute
Returns a new instance of GeneratedAttribute.
6 7 8 9 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 6 def initialize(name, type) @name = name @type = type.to_sym end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 4 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 4 def type @type end |
Instance Method Details
#alter_definition ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 19 def alter_definition case type when :Text then "String, :text => true" when :Boolean then "TrueClass" else type end end |
#create_definition ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 11 def create_definition case type when :Text then "String :#{name}, :text => true" when :Boolean then "TrueClass :#{name}" else "#{type} :#{name}" end end |
#default ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 40 def default @default ||= case type when :integer then 1 when :float then 1.5 when :decimal then "9.99" when :datetime, :timestamp, :time then Time.now.to_s(:db) when :date then Date.today.to_s(:db) when :string then "MyString" when :text then "MyText" when :boolean then false else "" end end |
#field_type ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 27 def field_type @field_type ||= case type when :Integer, :Float, :BigDecimal, :FixNum, :Numeric then :text_field when :DateTime, :Time then :datetime_select when :Date then :date_select when :String then :text_field when :Text then :text_area when :Boolean, :TrueClass, :FalseClass then :check_box else :text_field end end |
#human_name ⇒ Object
55 56 57 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 55 def human_name name.to_s.humanize end |
#reference? ⇒ Boolean
59 60 61 |
# File 'lib/rails/generators/sequel/generated_attribute.rb', line 59 def reference? false end |