Class: ThumbsUp::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/thumbs_up/configuration.rb

Constant Summary collapse

OPTIONS =
[:voteable_relationship_name, :voter_relationship_name].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_nameObject

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_nameObject

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

Parameters:

  • option (Symbol)

    Key for a given attribute



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

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



46
47
48
# File 'lib/thumbs_up/configuration.rb', line 46

def merge(hash)
  to_hash.merge(hash)
end

#to_hashObject

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