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
76 77 78 79 80 |
# File 'lib/braque/model.rb', line 76 def client Hyperclient.new(api_root) do |client| client.headers['Http-Authorization'] = api_token end end |
#collection_method_name ⇒ Object
68 69 70 |
# File 'lib/braque/model.rb', line 68 def collection_method_name name.tableize end |
#create(params = {}) ⇒ Object
63 64 65 66 |
# File 'lib/braque/model.rb', line 63 def create(params = {}) response = client.method(collection_method_name).call._post("#{instance_method_name}" => params) new response end |
#find(options = {}) ⇒ Object
58 59 60 61 |
# File 'lib/braque/model.rb', line 58 def find( = {}) response = client.method(instance_method_name).call() new response end |
#instance_method_name ⇒ Object
72 73 74 |
# File 'lib/braque/model.rb', line 72 def instance_method_name collection_method_name.singularize end |
#list(options = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/braque/model.rb', line 52 def list( = {}) = Hash[.map { |k, v| [CGI.escape(k.to_s), v] }] response = client.method(collection_method_name).call() LinkedArray.new response, self end |