Module: Braque::Model::ClassMethods
- Includes:
- Collection, Relations
- Defined in:
- lib/braque/model.rb
Instance Method Summary collapse
- #client ⇒ Object
- #collection_method_name ⇒ Object
- #create(resource_params = {}, options = {}) ⇒ Object
- #find(options = {}) ⇒ Object
- #instance_method_name ⇒ Object
- #list(options = {}) ⇒ Object
Methods included from Relations
Instance Method Details
#client ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/braque/model.rb', line 125 def client raise 'Please define api_root for all Braque::Model classes' unless config[:api_root_url] Hyperclient.new(config[:api_root_url]) do |client| client.headers['Http-Authorization'] = config[:http_authorization_header] if config[:http_authorization_header] client.headers['Authorization'] = config[:authorization_header] if config[:authorization_header] client.headers['Accept'] = config[:accept_header] if config[:accept_header] end end |
#collection_method_name ⇒ Object
117 118 119 |
# File 'lib/braque/model.rb', line 117 def collection_method_name (config[:remote_resource_name].present? ? config[:remote_resource_name] : name).tableize end |
#create(resource_params = {}, options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/braque/model.rb', line 107 def create(resource_params = {}, = {}) response = client.method(collection_method_name) .call ._post( { instance_method_name.to_s => resource_params } .merge() ) new response end |
#find(options = {}) ⇒ Object
102 103 104 105 |
# File 'lib/braque/model.rb', line 102 def find( = {}) response = client.method(instance_method_name).call() new response end |
#instance_method_name ⇒ Object
121 122 123 |
# File 'lib/braque/model.rb', line 121 def instance_method_name collection_method_name.singularize end |
#list(options = {}) ⇒ Object
96 97 98 99 100 |
# File 'lib/braque/model.rb', line 96 def list( = {}) = Hash[.map { |k, v| [CGI.escape(k.to_s), v] }] response = client.method(collection_method_name).call() LinkedArray.new response, self end |