Class: AwsRecord::Generators::GeneratedAttribute
- Inherits:
-
Object
- Object
- AwsRecord::Generators::GeneratedAttribute
- 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].freeze
- INVALID_HKEY_TYPES =
%i[map_attr list_attr numeric_set_attr string_set_attr].freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #column_name ⇒ Object
- #field_type ⇒ Object
- #human_name ⇒ Object
-
#initialize(name, type = :string_attr, options = {}) ⇒ GeneratedAttribute
constructor
A new instance of GeneratedAttribute.
-
#password_digest? ⇒ Boolean
Methods used by rails scaffolding.
- #polymorphic? ⇒ Boolean
Constructor Details
#initialize(name, type = :string_attr, options = {}) ⇒ GeneratedAttribute
Returns a new instance of GeneratedAttribute.
109 110 111 112 113 114 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 109 def initialize(name, type = :string_attr, = {}) @name = name @type = type @options = @digest = .delete(:digest) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 9 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 8 def type @type end |
Class Method Details
.parse(field_definition) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 22 def parse(field_definition) name, type, opts = field_definition.split(':') type ||= 'string' if OPTS.any? { |opt| type.include? opt } opts = type type = 'string' end opts = opts.split(',') if opts type, opts = (name, type, opts) validate_opt_combs(name, type, opts) new(name, type, opts) end |
Instance Method Details
#column_name ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 125 def column_name if @name == 'password_digest' 'password' else @name end end |
#field_type ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 11 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_name ⇒ Object
133 134 135 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 133 def human_name name.humanize end |
#password_digest? ⇒ Boolean
Methods used by rails scaffolding
117 118 119 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 117 def password_digest? @digest end |
#polymorphic? ⇒ Boolean
121 122 123 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 121 def polymorphic? false end |