Module: StandardAPI
- Defined in:
- lib/standard_api.rb,
lib/standard_api/test_case/show_tests.rb,
lib/standard_api/test_case/index_tests.rb,
lib/standard_api/test_case/create_tests.rb,
lib/standard_api/test_case/update_tests.rb,
lib/standard_api/test_case/destroy_tests.rb,
lib/standard_api/test_case/calculate_tests.rb
Defined Under Namespace
Modules: TestCase
Class Method Summary collapse
Instance Method Summary collapse
- #calculate ⇒ Object
- #create ⇒ Object
-
#current_mask ⇒ Object
Override if you want to support masking.
- #destroy ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Class Method Details
.included(klass) ⇒ Object
16 17 18 19 20 |
# File 'lib/standard_api.rb', line 16 def self.included(klass) klass.hide_action :current_mask klass.helper_method :includes, :orders klass.prepend_view_path(File.join(File.dirname(__FILE__), 'standard_api', 'views')) end |
Instance Method Details
#calculate ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/standard_api.rb', line 27 def calculate @calculations = resources.reorder(nil).pluck(*calculate_selects).map do |c| if c.is_a?(Array) c.map { |v| v.is_a?(BigDecimal) ? v.to_f : v } else c.is_a?(BigDecimal) ? c.to_f : c end end render json: @calculations end |
#create ⇒ Object
43 44 45 46 47 |
# File 'lib/standard_api.rb', line 43 def create @record = model.new(model_params) instance_variable_set("@#{model.model_name.singular}", @record) render :show, status: @record.save ? :created : :bad_request end |
#current_mask ⇒ Object
Override if you want to support masking
61 62 63 |
# File 'lib/standard_api.rb', line 61 def current_mask @current_mask ||= {} end |
#destroy ⇒ Object
55 56 57 58 |
# File 'lib/standard_api.rb', line 55 def destroy resources.find(params[:id]).destroy! render nothing: true, status: :no_content end |
#index ⇒ Object
22 23 24 25 |
# File 'lib/standard_api.rb', line 22 def index @records = resources.limit(params[:limit]).offset(params[:offset]).sort(orders) instance_variable_set("@#{model.model_name.plural}", @records) end |
#show ⇒ Object
38 39 40 41 |
# File 'lib/standard_api.rb', line 38 def show @record = resources.find(params[:id]) instance_variable_set("@#{model.model_name.singular}", @record) end |
#update ⇒ Object
49 50 51 52 53 |
# File 'lib/standard_api.rb', line 49 def update @record = resources.find(params[:id]) instance_variable_set("@#{model.model_name.singular}", @record) render :show, status: @record.update_attributes(model_params) ? :ok : :bad_request end |