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)
- INVALID_HKEY_TYPES =
%i(map_attr list_attr numeric_set_attr string_set_attr)
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.
100 101 102 103 104 105 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 100 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.
7 8 9 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 8 def @options end |
#type ⇒ Object (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 = (name, type, opts) validate_opt_combs(name, type, opts) new(name, type, opts) end |
Instance Method Details
#column_name ⇒ Object
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_type ⇒ Object
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_name ⇒ Object
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
108 109 110 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 108 def password_digest? @digest end |
#polymorphic? ⇒ Boolean
112 113 114 |
# File 'lib/generators/aws_record/generated_attribute.rb', line 112 def polymorphic? false end |