Module: Sandwich::Model::Base
- Included in:
- Machinist
- Defined in:
- lib/sandwich/model/base.rb
Instance Method Summary collapse
- #definition(str) ⇒ Object
- #materialize!(match) ⇒ Object
- #Materializer(name) ⇒ Object
- #record(name, args) ⇒ Object
-
#record!(name, args) ⇒ Object
Create a record.
Instance Method Details
#definition(str) ⇒ Object
35 36 37 |
# File 'lib/sandwich/model/base.rb', line 35 def definition(str) DefinitionScanner.new(str, Sandwich::Model.attribute_separators) end |
#materialize!(match) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sandwich/model/base.rb', line 17 def materialize!(match) determiner, model, values = definition(match).model_definition return match if model.nil? if creator?(determiner) if determiner.to_i == 1 record!(model, values) else determiner.times.map { record!(model.singularize, values) } end else record(model, values) end rescue ModelNotFoundError return match end |
#Materializer(name) ⇒ Object
13 14 15 |
# File 'lib/sandwich/model/base.rb', line 13 def Materializer(name) Sandwich::Model::Materializer[name] end |
#record(name, args) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/sandwich/model/base.rb', line 49 def record(name, args) materializer = Materializer(name) raise ModelNotFoundError, "No model found for '#{name}'" if materializer.nil? materializer.get(args) end |
#record!(name, args) ⇒ Object
Create a record
41 42 43 44 45 46 47 |
# File 'lib/sandwich/model/base.rb', line 41 def record!(name, args) materializer = Materializer(name) raise ModelNotFoundError, "No model found for '#{name}'" if materializer.nil? materializer.new(args) end |