Module: OceanDynamo::Schema
- Included in:
- Table
- Defined in:
- lib/ocean-dynamo/schema.rb
Instance Method Summary collapse
- #attribute(name, type = :string, default: nil, **extra) ⇒ Object
- #compute_table_name ⇒ Object
- #define_attribute_accessors(name) ⇒ Object
-
#dynamo_schema ⇒ Object
———————————————————.
- #table_full_name ⇒ Object
Instance Method Details
#attribute(name, type = :string, default: nil, **extra) ⇒ Object
35 36 37 38 39 |
# File 'lib/ocean-dynamo/schema.rb', line 35 def attribute(name, type=:string, default: nil, **extra) raise DangerousAttributeError, "#{name} is defined by OceanDynamo" if self.dangerous_attributes.include?(name.to_s) attr_accessor name fields[name.to_s] = {type: type, default: default}.merge(extra) end |
#compute_table_name ⇒ Object
25 26 27 |
# File 'lib/ocean-dynamo/schema.rb', line 25 def compute_table_name name.pluralize.underscore.gsub('/', '_') end |
#define_attribute_accessors(name) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ocean-dynamo/schema.rb', line 17 def define_attribute_accessors(name) name = name.to_s self.class_eval "def #{name}; read_attribute('#{name}'); end" self.class_eval "def #{name}=(value); write_attribute('#{name}', value); end" self.class_eval "def #{name}?; read_attribute('#{name}').present?; end" end |
#dynamo_schema ⇒ Object
Class methods
10 11 12 13 14 |
# File 'lib/ocean-dynamo/schema.rb', line 10 def dynamo_schema(*) super # Finally return the full table name table_full_name end |
#table_full_name ⇒ Object
30 31 32 |
# File 'lib/ocean-dynamo/schema.rb', line 30 def table_full_name "#{table_name_prefix}#{table_name}#{table_name_suffix}" end |