Module: FlowMachine::Workflow::ModelExtension
- Defined in:
- lib/flow_machine/workflow/model_extension.rb
Instance Method Summary collapse
-
#create_scopes_on(content_class) ⇒ Object
resolves to class Model def self.published where(status: ‘published’) end.
Instance Method Details
#create_scopes_on(content_class) ⇒ Object
resolves to class Model
def self.published
where(status: 'published')
end
def published?
self.status == 'published'
end
end
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/flow_machine/workflow/model_extension.rb', line 14 def create_scopes_on(content_class) state_method = self.state_method state_names.each do |status| # Don't add the scope classes if `where` is not defined since it means # you're likely not in a ORM class. if content_class.respond_to?(:where) content_class.singleton_class.send(:define_method, status) do where(state_method => status) end end content_class.send(:define_method, "#{status}?") do public_send(state_method) == status end end end |