class TheGrid::Api::Command
Public Class Methods
build(cmd)
click to toggle source
# File lib/the_grid/api/command.rb, line 25 def self.build(cmd) scope = scopes.detect do |scope| "#{scope}/#{cmd}".camelize.constantize rescue nil end raise ArgumentError, %{ Command "#{cmd}" is unknown } if scope.nil? "#{scope}/#{cmd}".camelize.constantize.new end
find(cmd)
click to toggle source
# File lib/the_grid/api/command.rb, line 12 def self.find(cmd) @@commands ||= {} @@commands[cmd] ||= build(cmd) end
register_lookup_scope(scope)
click to toggle source
# File lib/the_grid/api/command.rb, line 17 def self.register_lookup_scope(scope) scopes.unshift(scope).uniq! end
scopes()
click to toggle source
# File lib/the_grid/api/command.rb, line 21 def self.scopes @@scopes ||= ["the_grid/api/command"] end
Public Instance Methods
batch?()
click to toggle source
# File lib/the_grid/api/command.rb, line 37 def batch? @is_batch ||= self.class.name.demodulize.starts_with?('Batch') end
contextualize(relation, params)
click to toggle source
# File lib/the_grid/api/command.rb, line 41 def contextualize(relation, params) {} end
execute_on(relation, params)
click to toggle source
# File lib/the_grid/api/command.rb, line 33 def execute_on(relation, params) run_on(relation, configure(relation, params)) end
Protected Instance Methods
column_for(relation, field_name)
click to toggle source
# File lib/the_grid/api/command.rb, line 55 def column_for(relation, field_name) table, field = field_name.to_s.split('.') if field.blank? relation.table[field_name] elsif relation.reflections[table.to_sym] relation.reflections[table.to_sym].klass.arel_table[field] else raise "Unable to find column for #{field_name}" end end
configure(relation, params)
click to toggle source
# File lib/the_grid/api/command.rb, line 51 def configure(relation, params) params end
run_on(relation, params)
click to toggle source
# File lib/the_grid/api/command.rb, line 47 def run_on(relation, params) raise "Method \"#{inspect}::run_on\" should be implemented by child class" end