Module: Eco::API::Common::ClassHierarchy
- Includes:
- ClassHelpers
- Included in:
- Session::Batch::BasePolicy, Session::Config::Workflow
- Defined in:
- lib/eco/api/common/class_hierarchy.rb
Overview
Helpers for dynammic generation of classes based on a hierarchical model
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
-
#model_attrs ⇒ Array<String>
The
keysof the current class'model. -
#parse_model(model) ⇒ Hash?
Thanks to this step the format on the declaration of the model is flexible.
Methods included from Language::Klass::InheritableClassVars
#inheritable_attrs, #inheritable_class_vars, #inherited
Methods included from Language::Klass::Naming
#instance_variable_name, #to_constant
Methods included from Language::Klass::Hierarchy
Methods included from Language::Klass::Builder
Methods included from Language::Klass::Resolver
#class_resolver, #resolve_class
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
9 10 11 |
# File 'lib/eco/api/common/class_hierarchy.rb', line 9 def model @model end |
Instance Method Details
#model_attrs ⇒ Array<String>
Returns the keys of the current class' model.
17 18 19 |
# File 'lib/eco/api/common/class_hierarchy.rb', line 17 def model_attrs model&.keys || [] end |
#parse_model(model) ⇒ Hash?
Thanks to this step the format on the declaration of the model is flexible
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/eco/api/common/class_hierarchy.rb', line 24 def parse_model(model) case model when String parse_model(model.to_sym) when Symbol {model => nil} when Hash model.transform_keys(&:to_sym) when Enumerable model.each_with_object({}) do |sub, hash| hash.merge!(parse_model(sub)) end when NilClass nil else raise "Incorrect model declaration, allowed String, Symbol, Hash and Enumerable. Given: #{model.class}" end end |