Module: Oare::Resource::ClassMethods
- Defined in:
- lib/active_resource_override/base.rb
Overview
Instance Methods
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#associations ⇒ Object
Returns the value of attribute associations.
-
#nested_attributes ⇒ Object
Returns the value of attribute nested_attributes.
Instance Method Summary collapse
- #accepts_nested_attributes_for(association_id, options = {}) ⇒ Object
- #connection(refresh = true) ⇒ Object
- #create_path(path_options = {}, query_options = nil) ⇒ Object
- #has_many(association_id, options = {}) ⇒ Object
- #oauth_connection(refresh = true) ⇒ Object
- #set_default_values ⇒ Object
- #update_path(id, path_options = {}, query_options = nil) ⇒ Object
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
123 124 125 |
# File 'lib/active_resource_override/base.rb', line 123 def access_token @access_token end |
#associations ⇒ Object
Returns the value of attribute associations.
124 125 126 |
# File 'lib/active_resource_override/base.rb', line 124 def associations @associations end |
#nested_attributes ⇒ Object
Returns the value of attribute nested_attributes.
125 126 127 |
# File 'lib/active_resource_override/base.rb', line 125 def nested_attributes @nested_attributes end |
Instance Method Details
#accepts_nested_attributes_for(association_id, options = {}) ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/active_resource_override/base.rb', line 158 def accepts_nested_attributes_for(association_id, = {}) nested_attributes["#{association_id}_attributes"] = association_id define_method("#{association_id}_attributes=") do |*args| # TODO end define_method("#{association_id}_attributes") do nested_attributes_values["#{association_id}_attributes"] end end |
#connection(refresh = true) ⇒ Object
174 175 176 |
# File 'lib/active_resource_override/base.rb', line 174 def connection(refresh = true) self.access_token ? self.oauth_connection : super end |
#create_path(path_options = {}, query_options = nil) ⇒ Object
188 189 190 191 192 193 |
# File 'lib/active_resource_override/base.rb', line 188 def create_path( = {}, = nil) path = .delete(:path) = return collection_path(, ) unless path "/#{path}.#{format.extension}#{query_string()}" end |
#has_many(association_id, options = {}) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/active_resource_override/base.rb', line 132 def has_many(association_id, = {}) class_name = [:class_name] || association_id.to_s.singularize.camelize associations << class_name.constantize define_method(association_id) do |*args| current_value = instance_variable_get("@#{association_id}".to_sym) return current_value if current_value begin resource = class_name.constantize rescue resource = find_or_create_resource_for_collection(class_name) end value = if self.new_record? then [resource.new] else # TODO: # Request for users of account # Use an instance variable version of the access token # end instance_variable_set( "@#{association_id}".to_sym, value) end end |
#oauth_connection(refresh = true) ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/active_resource_override/base.rb', line 178 def oauth_connection(refresh = true) associations.each do |model_constant| model_constant.access_token = self.access_token end if associations @connection = Oare::Connection.new(self.access_token) if @connection.nil? || refresh @connection.timeout = timeout if timeout @connection end |
#set_default_values ⇒ Object
127 128 129 130 |
# File 'lib/active_resource_override/base.rb', line 127 def set_default_values self.nested_attributes ||= {} self.associations ||= [] end |
#update_path(id, path_options = {}, query_options = nil) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/active_resource_override/base.rb', line 195 def update_path(id, = {}, = nil) path = .delete(:path) = return element_path(id, , ) unless path "/#{path}.#{format.extension}#{query_string()}" end |