Class: Buezli::Api::Client::Record
- Inherits:
-
Object
- Object
- Buezli::Api::Client::Record
- Defined in:
- lib/buezli/api/client/record.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#raw_attributes ⇒ Object
readonly
Returns the value of attribute raw_attributes.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #deleted? ⇒ Boolean
- #id ⇒ Object
-
#initialize(attributes:, model_name:, schema:, api_client: nil, client: nil) ⇒ Record
constructor
A new instance of Record.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attributes:, model_name:, schema:, api_client: nil, client: nil) ⇒ Record
Returns a new instance of Record.
7 8 9 10 11 12 13 |
# File 'lib/buezli/api/client/record.rb', line 7 def initialize(attributes:, model_name:, schema:, api_client: nil, client: nil) @raw_attributes = (attributes || {}).with_indifferent_access @model_name = model_name @api_client = api_client || client @schema = schema raise ArgumentError, "api_client is required" unless @api_client end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
31 32 33 34 35 |
# File 'lib/buezli/api/client/record.rb', line 31 def method_missing(method, *args, &block) return super unless args.empty? && block.nil? && schema.declared_field?(model_name, method) read_value(method.to_s) end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
5 6 7 |
# File 'lib/buezli/api/client/record.rb', line 5 def api_client @api_client end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
5 6 7 |
# File 'lib/buezli/api/client/record.rb', line 5 def model_name @model_name end |
#raw_attributes ⇒ Object (readonly)
Returns the value of attribute raw_attributes.
5 6 7 |
# File 'lib/buezli/api/client/record.rb', line 5 def raw_attributes @raw_attributes end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/buezli/api/client/record.rb', line 5 def schema @schema end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 |
# File 'lib/buezli/api/client/record.rb', line 23 def [](key) raw_attributes[key] end |
#deleted? ⇒ Boolean
19 20 21 |
# File 'lib/buezli/api/client/record.rb', line 19 def deleted? raw_attributes[:_deleted] == true end |
#id ⇒ Object
15 16 17 |
# File 'lib/buezli/api/client/record.rb', line 15 def id raw_attributes[:id] end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
37 38 39 |
# File 'lib/buezli/api/client/record.rb', line 37 def respond_to_missing?(method, include_private = false) schema.declared_field?(model_name, method) || super end |
#to_h ⇒ Object
27 28 29 |
# File 'lib/buezli/api/client/record.rb', line 27 def to_h raw_attributes.to_h end |