Class: Essay::AbstractCollection

Inherits:
Object
  • Object
show all
Includes:
ModelHelper
Defined in:
lib/essay/abstract_collection.rb

Direct Known Subclasses

AssociationCollection, AttributeCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (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_hashObject



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