Class: Toggle

Inherits:
Object
  • Object
show all
Defined in:
lib/toggle/parser/yaml.rb,
lib/toggle.rb,
lib/toggle/parser.rb,
lib/toggle/version.rb,
lib/toggle/compiler.rb

Overview

YAML Parser handles erb parsing first, then loads the content to yaml

Defined Under Namespace

Modules: Parser Classes: Compiler

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Toggle

Returns a new instance of Toggle.



14
15
16
17
18
# File 'lib/toggle.rb', line 14

def initialize attributes = {}
  attributes.keys.each do |attribute|
    self.send "#{attribute}=", attributes[attribute]
  end
end

Instance Attribute Details

#config_filepathObject

Returns the value of attribute config_filepath.



12
13
14
# File 'lib/toggle.rb', line 12

def config_filepath
  @config_filepath
end

#config_parsersObject

Returns the value of attribute config_parsers.



11
12
13
# File 'lib/toggle.rb', line 11

def config_parsers
  @config_parsers
end

#keyObject



29
30
31
# File 'lib/toggle.rb', line 29

def key
  (@key || key_from_file).try(:to_sym)
end

#key_filepathObject

Returns the value of attribute key_filepath.



10
11
12
# File 'lib/toggle.rb', line 10

def key_filepath
  @key_filepath
end

#key_parsersObject

Returns the value of attribute key_parsers.



9
10
11
# File 'lib/toggle.rb', line 9

def key_parsers
  @key_parsers
end

Instance Method Details

#[](attribute) ⇒ Object



20
21
22
# File 'lib/toggle.rb', line 20

def [] attribute
  config[attribute]
end

#configObject



33
34
35
# File 'lib/toggle.rb', line 33

def config
  configs[key]
end

#configsObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/toggle.rb', line 37

def configs
  return @configs if defined?(@configs) && configs_clean?

  @configs = HashWithIndifferentAccess.new(
    Toggle::Compiler.new(
      config_filepath,
      config_parsers
    ).parsed_content
  )
  configs_clean!
  @configs
end

#using(temporary_key) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Toggle)

    the object that the method was called on



50
51
52
53
54
55
56
# File 'lib/toggle.rb', line 50

def using temporary_key
  return unless block_given?

  previous_key, self.key = self.key, temporary_key
  yield self
  self.key = previous_key
end