Class: Ruboss::Generator::GeneratedAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboss4ruby/generated_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ GeneratedAttribute

Returns a new instance of GeneratedAttribute.



6
7
8
9
# File 'lib/ruboss4ruby/generated_attribute.rb', line 6

def initialize(name, type)
  @name, @type = name, type.to_sym
  @flex_name = name.camelcase(:lower)      
end

Instance Attribute Details

#flex_nameObject

Returns the value of attribute flex_name.



4
5
6
# File 'lib/ruboss4ruby/generated_attribute.rb', line 4

def flex_name
  @flex_name
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/ruboss4ruby/generated_attribute.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/ruboss4ruby/generated_attribute.rb', line 4

def type
  @type
end

Instance Method Details

#default(prefix = '') ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruboss4ruby/generated_attribute.rb', line 24

def default(prefix = '')
  @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 prefix + name.camelize + "String"
    when :text                        then prefix + name.camelize + "Text"
    when :boolean                     then false
    else
      ""
  end      
end

#field_typeObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruboss4ruby/generated_attribute.rb', line 11

def field_type
  @field_type ||= case type
    when :integer, :float, :decimal   then :text_field
    when :datetime, :timestamp, :time then :datetime_select
    when :date                        then :date_select
    when :string                      then :text_field
    when :text                        then :text_area
    when :boolean                     then :check_box
    else
      :text_field
  end      
end

#flex_default(prefix = '') ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/ruboss4ruby/generated_attribute.rb', line 50

def flex_default(prefix = '')
  @flex_default = case type
    when :integer, :float, :decimal   then '0'
    when :string, :text               then '""'
    when :boolean                     then 'false'
    else
      'null'
  end
end

#flex_typeObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/ruboss4ruby/generated_attribute.rb', line 39

def flex_type
  @flex_type = case type
    when :integer                     then 'int'
    when :date, :datetime, :time      then 'Date'
    when :boolean                     then 'Boolean'
    when :float, :decimal             then 'Number'
    else
      'String'
  end
end