Module: ActiveTrail::Controller
- Defined in:
- lib/active_trail/controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_new_resource ⇒ Object
- #create_resource(object) ⇒ Object
- #find_collection ⇒ Object
- #find_resource ⇒ Object
- #scoped_collection ⇒ Object
- #update(options = {}, &block) ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_trail/controller.rb', line 3 def self.included(base) if base.instance_methods.include?(:collection) Trailblazer::Operation::Controller.instance_eval do begin # As activeadmin has a collection controller method we remove it # so we don't override original method and use `trb_collection` # unless respond_to?(:trb_collection) alias_method :trb_collection, :collection remove_method :collection rescue NameError # So you're doing a null rescue here, do you like it? NO! # But every modification on a AA related class, this class is reloaded # and was trying make the alias_method and raise this exception # don't know if its a rails issue, or my code issue # if someone knows how to fix without this (unpolite) nil rescue # please open an issue / PR end end base.include Trailblazer::Operation::Controller end require 'trailblazer/operation/controller/active_record' base.include Trailblazer::Operation::Controller::ActiveRecord # named instance variables. end |
Instance Method Details
#build_new_resource ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_trail/controller.rb', line 51 def build_new_resource if params[:action] == 'create' run "#{trailblazer_operation_name}::Create".constantize do |op| return op.model end.else do |op| return op.contract end else form "#{trailblazer_operation_name}::Create".constantize do |op| return @contract end end end |
#create_resource(object) ⇒ Object
65 66 67 68 69 |
# File 'lib/active_trail/controller.rb', line 65 def create_resource(object) run_create_callbacks object do return object end end |
#find_collection ⇒ Object
33 34 35 36 37 |
# File 'lib/active_trail/controller.rb', line 33 def find_collection trb_collection "#{trailblazer_operation_name}::Index".constantize do |op| return @collection end end |
#find_resource ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_trail/controller.rb', line 39 def find_resource if params.has_key?(:id) run "#{trailblazer_operation_name}::Show".constantize do |op| return op.model end else form "#{trailblazer_operation_name}::Create".constantize do |op| return op.contract end end end |
#scoped_collection ⇒ Object
27 28 29 30 31 |
# File 'lib/active_trail/controller.rb', line 27 def scoped_collection trb_collection "#{trailblazer_operation_name}::Index".constantize do |op| return @collection end end |
#update(options = {}, &block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/active_trail/controller.rb', line 71 def update(={}, &block) object = resource run "#{trailblazer_operation_name}::Update".constantize do |op| [:location] ||= smart_resource_url respond_with(op.model, ) end.else do |op| instance_variable_set("@#{trailblazer_model_name}".to_sym, op.contract) respond_with(op, ) end end |