module OceanDynamo::Schema
Public Instance Methods
attribute(name, type=:string, default: nil, **extra)
click to toggle source
# 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()
click to toggle source
# File lib/ocean-dynamo/schema.rb, line 25 def compute_table_name name.pluralize.underscore.gsub('/', '_') end
define_attribute_accessors(name)
click to toggle source
# 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(*)
click to toggle source
Class methods
Calls superclass method
# File lib/ocean-dynamo/schema.rb, line 10 def dynamo_schema(*) super # Finally return the full table name table_full_name end
global_secondary_index(hash_key, range_key=nil, projection: :keys_only, read_capacity_units: table_read_capacity_units, write_capacity_units: table_write_capacity_units)
click to toggle source
# File lib/ocean-dynamo/schema.rb, line 42 def global_secondary_index(hash_key, range_key=nil, projection: :keys_only, read_capacity_units: table_read_capacity_units, write_capacity_units: table_write_capacity_units) if range_key name = "#{hash_key}_#{range_key}_global" keys = [hash_key.to_s, range_key.to_s] else name = "#{hash_key}_global" keys = [hash_key.to_s] end self.global_secondary_indexes[name] = { "keys" => keys, "projection_type" => projection.to_s.upcase, "read_capacity_units" => read_capacity_units, "write_capacity_units" => write_capacity_units } end
table_full_name()
click to toggle source
# File lib/ocean-dynamo/schema.rb, line 30 def table_full_name "#{table_name_prefix}#{table_name}#{table_name_suffix}" end