Class: ThumbsUp::Configuration
- Inherits:
-
Object
- Object
- ThumbsUp::Configuration
- Defined in:
- lib/thumbs_up/configuration.rb
Constant Summary collapse
- OPTIONS =
[:voteable_relationship_name, :voter_relationship_name].freeze
Instance Attribute Summary collapse
-
#voteable_relationship_name ⇒ Object
Specify the name of the relationship from voted on things to voters.
-
#voter_relationship_name ⇒ Object
Specify the name of the relationship from voters to voted on things Default is votes In order to have a model that votes on itself, e.g.
Instance Method Summary collapse
-
#[](option) ⇒ Object
Allows config options to be read like a hash.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with
hash. -
#to_hash ⇒ Object
Returns a hash of all configurable options.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
22 23 24 25 26 |
# File 'lib/thumbs_up/configuration.rb', line 22 def initialize # these defaults can be overridden in the ThumbsUp.config block @voteable_relationship_name = :votes @voter_relationship_name = :votes end |
Instance Attribute Details
#voteable_relationship_name ⇒ Object
Specify the name of the relationship from voted on things to voters. Default is votes In order to have a model that votes on itself,
e.g. Users vote on Users,
must change :voteable_relationship_name or :voter_relationship_name
to a non-default value
12 13 14 |
# File 'lib/thumbs_up/configuration.rb', line 12 def voteable_relationship_name @voteable_relationship_name end |
#voter_relationship_name ⇒ Object
Specify the name of the relationship from voters to voted on things Default is votes In order to have a model that votes on itself,
e.g. Users vote on Users,
must change :voteable_relationship_name or :voter_relationship_name
to a non-default value
20 21 22 |
# File 'lib/thumbs_up/configuration.rb', line 20 def voter_relationship_name @voter_relationship_name end |
Instance Method Details
#[](option) ⇒ Object
Allows config options to be read like a hash
31 32 33 |
# File 'lib/thumbs_up/configuration.rb', line 31 def [](option) send(option) end |
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with hash
46 47 48 |
# File 'lib/thumbs_up/configuration.rb', line 46 def merge(hash) to_hash.merge(hash) end |
#to_hash ⇒ Object
Returns a hash of all configurable options
36 37 38 39 40 41 |
# File 'lib/thumbs_up/configuration.rb', line 36 def to_hash OPTIONS.inject({}) do |hash, option| hash[option.to_sym] = self.send(option) hash end end |