Class: Resourceful::Model::Json
- Defined in:
- lib/resourceful/model/json.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Class Method Summary collapse
- .get(path, params, search = nil, force = false, &block) ⇒ Object
- .get_collection(path, params, search = nil, force = false, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(json = nil) ⇒ Json
constructor
A new instance of Json.
Methods inherited from Base
agent, #attributes, cleanup_name, #data, #destroy, find, get_namespaced_klass, namespaces, #new_record?, #save, #update_attributes
Methods included from AttributeTypes
Constructor Details
#initialize(json = nil) ⇒ Json
Returns a new instance of Json.
32 33 34 35 |
# File 'lib/resourceful/model/json.rb', line 32 def initialize(json=nil) raise Resourceful::Exceptions::ModelError, "trying to initialize a Resourceful::Model::Json model with '#{json.class.name}' data" unless json.nil? || json.kind_of?(::Hash) @data = json end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
9 10 11 |
# File 'lib/resourceful/model/json.rb', line 9 def json @json end |
Class Method Details
.get(path, params, search = nil, force = false, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/resourceful/model/json.rb', line 11 def self.get(path, params, search=nil, force=false, &block) opts = { :format => 'json', :params => params || {}, :force => force, :on_response => block } new(get_result_data(super(path, opts), search)) end |
.get_collection(path, params, search = nil, force = false, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/resourceful/model/json.rb', line 20 def self.get_collection(path, params, search=nil, force=false, &block) opts = { :format => 'json', :params => params || {}, :force => force, :on_response => block } super(path, opts) do |data| data.collect {|item| get_result_data(item, search) } end end |