Module: DisablePrefixCheck::ClassMethods
- Defined in:
- lib/active_resource/disable_prefix_check.rb
Instance Method Summary collapse
- #check_prefix_options(options) ⇒ Object
-
#conditional_prefix(resource, flexible = false) ⇒ Object
‘flexible = true` is hack to allow multiple things through the same AR class.
- #new_record(record) ⇒ Object
Instance Method Details
#check_prefix_options(options) ⇒ Object
5 6 |
# File 'lib/active_resource/disable_prefix_check.rb', line 5 def () end |
#conditional_prefix(resource, flexible = false) ⇒ Object
‘flexible = true` is hack to allow multiple things through the same AR class
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_resource/disable_prefix_check.rb', line 9 def conditional_prefix(resource, flexible = false) resource_id = "#{resource}_id".to_sym resource_type = flexible ? ":#{resource}" : resource.to_s.pluralize init_prefix_explicit resource_type, resource_id define_singleton_method :prefix do | = {}| resource_type = [resource] if flexible [resource_id].nil? ? "/api/" : "/api/#{resource_type}/#{[resource_id]}/" end define_singleton_method :instantiate_record do |record, = {}| new_record(record).tap do |resource| resource. = unless .blank? end end end |
#new_record(record) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/active_resource/disable_prefix_check.rb', line 28 def new_record(record) if ActiveSupport::VERSION::MAJOR == 3 && ActiveSupport::VERSION::MINOR == 0 new(record) else new(record, true) end end |