Class: Essay::AbstractCollection
- Inherits:
-
Object
- Object
- Essay::AbstractCollection
- Includes:
- ModelHelper
- Defined in:
- lib/essay/abstract_collection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(env) ⇒ AbstractCollection
constructor
A new instance of AbstractCollection.
- #to_hash ⇒ Object
Methods included from ModelHelper
#active_record, #active_record_associations, #active_record_attributes, #active_record_features, #active_record_traits, #traits
Constructor Details
#initialize(env) ⇒ AbstractCollection
Returns a new instance of AbstractCollection.
12 13 14 15 16 |
# File 'lib/essay/abstract_collection.rb', line 12 def initialize(env) @env = env @active_record = env.fetch(:active_record) @features_for = {} end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
10 11 12 |
# File 'lib/essay/abstract_collection.rb', line 10 def env @env end |
Instance Method Details
#[](name) ⇒ Object
18 19 20 |
# File 'lib/essay/abstract_collection.rb', line 18 def [](name) @features_for[name.to_sym] ||= construct_features(name) end |
#to_hash ⇒ Object
22 23 24 25 26 |
# File 'lib/essay/abstract_collection.rb', line 22 def to_hash @features_for.each_with_object({}) do |(k, v), memo| memo[k] = v.to_hash end end |