Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Policy
- class << self
- def rename_attributes(&block)
- @root ||= {}
- @block = block
- end
- def mapped_attributes
- instance_eval(&@block)
- @root
- end
- def rename(from:, to:, &attribues_block)
- children = instance_eval(&attribues_block) if block_given?
- @root[from] = {
- to: to,
- children: children,
- }
- @root
- end
- def delegates_renaming_to(policy_klass)
- policy_klass.mapped_attributes
- end
- end
- end
- class StockGroupPolicy < Policy
- rename_attributes do
- rename from: :batch, to: :stock_group_attributes
- rename from: :batch_id, to: :stock_group_id
- end
- end
- class StockAdjustmentLineItemPolicy < Policy
- rename_attributes do
- rename from: :stock_trails, to: :stock_trails_attrs do
- delegates_renaming_to StockGroupPolicy
- end
- end
- end
- class StockAdjustmentPolicy < Policy
- rename_attributes do
- rename from: :stock_adjustment_line_items, to: :stock_adjustment_line_items_attrs do
- delegates_renaming_to StockAdjustmentLineItemPolicy
- end
- end
- end
- StockAdjustmentPolicy.mapped_attributes
Add Comment
Please, Sign In to add comment