Class: Materialize::Repo
- Inherits:
-
Object
- Object
- Materialize::Repo
- Includes:
- Utils
- Defined in:
- lib/materialize/repo.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(token = nil) ⇒ Repo
constructor
A new instance of Repo.
- #method_missing(query, *args) {|data| ... } ⇒ Object
Methods included from Utils
Constructor Details
#initialize(token = nil) ⇒ Repo
Returns a new instance of Repo.
7 8 9 |
# File 'lib/materialize/repo.rb', line 7 def initialize(token = nil) @token = token end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(query, *args) {|data| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/materialize/repo.rb', line 11 def method_missing(query, *args, &block) data_source_class = args[0] = args[1] || {} args_to_pass = [:args] data, builder_class, entity_class = process(data_source_class, query, args_to_pass) yield(data) if block_given? .delete(:args) # TODO: add a temporary bypass switch that skips builders # TODO: Switch to something like data['m_message'] to avoid collisions if [:skip_builders] if data.is_a?(Hash) and !data['message'].nil? Response.new data elsif data.is_a?(Array) entity_class.wrap(data) else entity_class.new(data) end else if data.is_a?(Hash) and !data['message'].nil? Response.new data elsif data.is_a?(Array) builder_class.build_all(data, self, ) else builder_class.build(data, self, ) end end end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/materialize/repo.rb', line 5 def token @token end |