Class: Dunlop::Generators::GeneratorHelpers::DunlopGeneratorAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/dunlop/generators/generator_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ DunlopGeneratorAttribute

Returns a new instance of DunlopGeneratorAttribute.



18
19
20
# File 'lib/dunlop/generators/generator_helpers.rb', line 18

def initialize(spec)
  @name, @type = spec.to_s.strip.split(':')
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/dunlop/generators/generator_helpers.rb', line 17

def name
  @name
end

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/dunlop/generators/generator_helpers.rb', line 41

def boolean?
  type == 'boolean'
end

#column_nameObject



26
27
28
# File 'lib/dunlop/generators/generator_helpers.rb', line 26

def column_name
  name.to_s.underscore.gsub(/\W/, '_')
end

#date?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/dunlop/generators/generator_helpers.rb', line 57

def date?
  type == 'date'
end

#float?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/dunlop/generators/generator_helpers.rb', line 49

def float?
  %w[decimal float].include?(type)
end

#form_typeObject



34
35
36
37
38
39
# File 'lib/dunlop/generators/generator_helpers.rb', line 34

def form_type
  case type
  when 'boolean' then 'boolean'
  else 'input'
  end
end

#integer?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/dunlop/generators/generator_helpers.rb', line 45

def integer?
  type == 'integer'
end

#numeric?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/dunlop/generators/generator_helpers.rb', line 53

def numeric?
  integer? or float?
end

#to_sObject



30
31
32
# File 'lib/dunlop/generators/generator_helpers.rb', line 30

def to_s
  name
end

#typeObject



22
23
24
# File 'lib/dunlop/generators/generator_helpers.rb', line 22

def type
  @type || 'string'
end