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.
116 117 118 |
# File 'lib/active_resource_override/base.rb', line 116 def access_token @access_token end |
#associations ⇒ Object
Returns the value of attribute associations.
117 118 119 |
# File 'lib/active_resource_override/base.rb', line 117 def associations @associations end |
#nested_attributes ⇒ Object
Returns the value of attribute nested_attributes.
118 119 120 |
# File 'lib/active_resource_override/base.rb', line 118 def nested_attributes @nested_attributes end |
Instance Method Details
#accepts_nested_attributes_for(association_id, options = {}) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/active_resource_override/base.rb', line 146 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
162 163 164 |
# File 'lib/active_resource_override/base.rb', line 162 def connection(refresh = true) self.access_token ? self.oauth_connection : super end |
#create_path(path_options = {}, query_options = nil) ⇒ Object
176 177 178 179 180 181 |
# File 'lib/active_resource_override/base.rb', line 176 def create_path( = {}, = nil) path = .delete(:path) = return collection_path(, ) unless path "/#{path}.#{format.extension}#{query_string()}" end |
#has_many(association_id, options = {}) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/active_resource_override/base.rb', line 125 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 resource = find_or_create_resource_for_collection(class_name) 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
166 167 168 169 170 171 172 173 174 |
# File 'lib/active_resource_override/base.rb', line 166 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
120 121 122 123 |
# File 'lib/active_resource_override/base.rb', line 120 def set_default_values self.nested_attributes ||= {} self.associations ||= [] end |
#update_path(id, path_options = {}, query_options = nil) ⇒ Object
183 184 185 186 187 188 |
# File 'lib/active_resource_override/base.rb', line 183 def update_path(id, = {}, = nil) path = .delete(:path) = return element_path(id, , ) unless path "/#{path}.#{format.extension}#{query_string()}" end |