Class: NoSE::EntityDSL
Overview
A helper class for DSL creation to avoid messing with Entity
Instance Method Summary collapse
-
#etc(size = 1) ⇒ Object
rubocop:enable MethodName.
-
#initialize(entity) ⇒ EntityDSL
constructor
A new instance of EntityDSL.
-
#PrimaryKey(*names) ⇒ Object
Specify a list of field names for the primary key.
Constructor Details
#initialize(entity) ⇒ EntityDSL
Returns a new instance of EntityDSL.
100 101 102 |
# File 'lib/nose/model/entity.rb', line 100 def initialize(entity) @entity = entity end |
Instance Method Details
#etc(size = 1) ⇒ Object
rubocop:enable MethodName
128 129 130 |
# File 'lib/nose/model/entity.rb', line 128 def etc(size = 1) @entity << Fields::HashField.new('**', size) end |
#PrimaryKey(*names) ⇒ Object
Specify a list of field names for the primary key
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/nose/model/entity.rb', line 107 def PrimaryKey(*names) # Unset the old keys and set new ones, # we dup because the fields are frozen @entity.fields.each_value do |field| next unless field.primary_key? field = field.dup field.primary_key = false @entity.fields[field.name] = field field.freeze end names.each do |name| field = @entity[name].dup field.primary_key = true @entity.fields[name] = field field.freeze end end |