Class: DearInventory::Parameters
- Inherits:
-
Object
- Object
- DearInventory::Parameters
- Extended by:
- IsASubclass, T::Sig
- Defined in:
- lib/dear_inventory/parameters.rb,
lib/dear_inventory/parameters/sale/show.rb,
lib/dear_inventory/parameters/sale/index.rb,
lib/dear_inventory/parameters/sale/delete.rb,
lib/dear_inventory/parameters/product/index.rb,
lib/dear_inventory/parameters/purchase/show.rb,
lib/dear_inventory/parameters/customer/index.rb,
lib/dear_inventory/parameters/purchase/index.rb,
lib/dear_inventory/parameters/advanced_purchase/show.rb,
lib/dear_inventory/parameters/product_availability/index.rb
Direct Known Subclasses
AdvancedPurchase::Show, Customer::Index, Product::Index, ProductAvailability::Index, Purchase::Index, Purchase::Show, Sale::Delete, Sale::Index, Sale::Show
Defined Under Namespace
Modules: AdvancedPurchase, Customer, Product, ProductAvailability, Purchase, Sale
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Parameters
constructor
A new instance of Parameters.
- #to_h ⇒ Object
Methods included from IsASubclass
Constructor Details
#initialize(params) ⇒ Parameters
Returns a new instance of Parameters.
10 11 12 13 |
# File 'lib/dear_inventory/parameters.rb', line 10 def initialize(params) @values = T.let({}, T::Hash[Symbol, T.untyped]) assign_params(params) end |
Class Method Details
.convert(resource_class, endpoint, params) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/dear_inventory/parameters.rb', line 40 def convert(resource_class, endpoint, params) params_class = endpoint_class(resource_class, endpoint) convert_with_params_class( endpoint: endpoint, params_class: params_class, resource_class: resource_class, params: params ) end |
.fields(fields) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/dear_inventory/parameters.rb', line 25 def fields(fields) const_set(:FIELDS, fields.freeze) fields.each do |name, specifications| define_method_for_validator(name, specifications) end end |
Instance Method Details
#to_h ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/dear_inventory/parameters.rb', line 180 def to_h self.class. const_get(:FIELDS). each_with_object({}) do |(field_name, specifications), hash| value = parameter_value(field_name, specifications) next if value.nil? hash[specifications[:property]] = value end end |