Class: AwsRecord::Generators::GeneratedAttribute

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

Constant Summary collapse

OPTS =
%w(hkey rkey persist_nil db_attr_name ddb_type default_value)
INVALID_HKEY_TYPES =
%i(map_attr list_attr numeric_set_attr string_set_attr)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type = :string_attr, options = {}) ⇒ GeneratedAttribute

Returns a new instance of GeneratedAttribute.



113
114
115
116
117
118
# File 'lib/generators/generated_attribute.rb', line 113

def initialize(name, type = :string_attr, options = {})
  @name = name
  @type = type
  @options = options
  @digest = options.delete(:digest)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/generators/generated_attribute.rb', line 20

def name
  @name
end

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/generators/generated_attribute.rb', line 21

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/generators/generated_attribute.rb', line 20

def type
  @type
end

Class Method Details

.parse(field_definition) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/generated_attribute.rb', line 35

def parse(field_definition)
  name, type, opts = field_definition.split(':')
  type = "string" if not type
  type, opts = "string", type if OPTS.any? { |opt| type.include? opt }

  opts = opts.split(',') if opts
  type, opts = parse_type_and_options(name, type, opts)
  validate_opt_combs(name, type, opts)

  new(name, type, opts)
end

Instance Method Details

#column_nameObject



129
130
131
132
133
134
135
# File 'lib/generators/generated_attribute.rb', line 129

def column_name
  if @name == "password_digest"
    "password"
  else
    @name
  end
end

#field_typeObject



23
24
25
26
27
28
29
30
31
# File 'lib/generators/generated_attribute.rb', line 23

def field_type
  case @type
    when :integer_attr then :number_field
    when :date_attr then :date_select
    when :datetime_attr then :datetime_select
    when :boolean_attr then :check_box
    else :text_field
  end
end

#human_nameObject



137
138
139
# File 'lib/generators/generated_attribute.rb', line 137

def human_name
  name.humanize
end

#password_digest?Boolean

Methods used by rails scaffolding

Returns:

  • (Boolean)


121
122
123
# File 'lib/generators/generated_attribute.rb', line 121

def password_digest?
  @digest
end

#polymorphic?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/generators/generated_attribute.rb', line 125

def polymorphic?
  false
end