Class: AwsRecord::Generators::GeneratedAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/aws_record/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.



100
101
102
103
104
105
# File 'lib/generators/aws_record/generated_attribute.rb', line 100

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.



7
8
9
# File 'lib/generators/aws_record/generated_attribute.rb', line 7

def name
  @name
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/generators/aws_record/generated_attribute.rb', line 8

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/generators/aws_record/generated_attribute.rb', line 7

def type
  @type
end

Class Method Details

.parse(field_definition) ⇒ Object



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

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



116
117
118
119
120
121
122
# File 'lib/generators/aws_record/generated_attribute.rb', line 116

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

#field_typeObject



10
11
12
13
14
15
16
17
18
# File 'lib/generators/aws_record/generated_attribute.rb', line 10

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



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

def human_name
  name.humanize
end

#password_digest?Boolean

Methods used by rails scaffolding

Returns:

  • (Boolean)


108
109
110
# File 'lib/generators/aws_record/generated_attribute.rb', line 108

def password_digest?
  @digest
end

#polymorphic?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/generators/aws_record/generated_attribute.rb', line 112

def polymorphic?
  false
end