Module: Braque::Model::ClassMethods
- Includes:
- Collection
- Defined in:
- lib/braque/model.rb
Instance Method Summary collapse
- #client ⇒ Object
- #collection_method_name ⇒ Object
- #create(params = {}) ⇒ Object
- #find(options = {}) ⇒ Object
- #instance_method_name ⇒ Object
- #list(options = {}) ⇒ Object
Instance Method Details
#client ⇒ Object
87 88 89 90 91 |
# File 'lib/braque/model.rb', line 87 def client Hyperclient.new(api_root) do |client| client.headers['Http-Authorization'] = api_token end end |
#collection_method_name ⇒ Object
79 80 81 |
# File 'lib/braque/model.rb', line 79 def collection_method_name name.tableize end |
#create(params = {}) ⇒ Object
74 75 76 77 |
# File 'lib/braque/model.rb', line 74 def create(params = {}) response = client.method(collection_method_name).call._post("#{instance_method_name}" => params) new response end |
#find(options = {}) ⇒ Object
69 70 71 72 |
# File 'lib/braque/model.rb', line 69 def find( = {}) response = client.method(instance_method_name).call() new response end |
#instance_method_name ⇒ Object
83 84 85 |
# File 'lib/braque/model.rb', line 83 def instance_method_name collection_method_name.singularize end |
#list(options = {}) ⇒ Object
63 64 65 66 67 |
# File 'lib/braque/model.rb', line 63 def list( = {}) = Hash[.map { |k, v| [CGI.escape(k.to_s), v] }] response = client.method(collection_method_name).call() LinkedArray.new response, self end |