Class: Bits::BitDeclaration
- Inherits:
-
Object
- Object
- Bits::BitDeclaration
- Defined in:
- lib/bits/bit_declaration.rb
Overview
Class used to manage state of a bit declaration file.
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#provider_data ⇒ Object
Returns the value of attribute provider_data.
Class Method Summary collapse
Instance Method Summary collapse
- #depends(atom, params = {}) ⇒ Object
-
#initialize(data) ⇒ BitDeclaration
constructor
A new instance of BitDeclaration.
- #parse_dependencies(data) ⇒ Object
- #parse_provider_data(data) ⇒ Object
-
#provided_by(provider_id, params = {}) ⇒ Object
Used inside bit declaration.
-
#provided_for(params = {}) ⇒ Object
Used inside bit declaration.
Constructor Details
#initialize(data) ⇒ BitDeclaration
Returns a new instance of BitDeclaration.
45 46 47 48 |
# File 'lib/bits/bit_declaration.rb', line 45 def initialize(data) @provider_data = parse_provider_data data @dependencies = parse_dependencies data end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
43 44 45 |
# File 'lib/bits/bit_declaration.rb', line 43 def dependencies @dependencies end |
#provider_data ⇒ Object
Returns the value of attribute provider_data.
43 44 45 |
# File 'lib/bits/bit_declaration.rb', line 43 def provider_data @provider_data end |
Class Method Details
.eval(reader) ⇒ Object
153 154 155 156 157 |
# File 'lib/bits/bit_declaration.rb', line 153 def self.eval(reader) data = YAML.load reader.read decl = self.new data decl end |
Instance Method Details
#depends(atom, params = {}) ⇒ Object
149 150 151 |
# File 'lib/bits/bit_declaration.rb', line 149 def depends(atom, params={}) @dependencies[atom] = params end |
#parse_dependencies(data) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/bits/bit_declaration.rb', line 103 def parse_dependencies(data) h = Hash.new depends = data[:depends] unless depends.nil? unless depends.kind_of? Array raise "Expected Array but got '#{depends.inspect}'" end depends.each do |item| unless item.kind_of? Hash raise "Expected Hash but got '#{item.inspect}'" end atom = item[:atom] if atom.nil? raise "Expected :atom to be not null in dependency" end unless h[atom].nil? raise "Dependency already specified: #{atom}" end h[atom] = BitDependency.new atom, item end end h end |
#parse_provider_data(data) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bits/bit_declaration.rb', line 50 def parse_provider_data(data) h = Hash.new provided_for = data[:provided_for] provided_by = data[:provided_by] unless provided_by.nil? unless provided_by.kind_of? Hash raise "Expected Hash but got '#{provided_by.inspect}'" end provided_by.each do |provider_id, parameters| unless parameters.kind_of? Hash raise "Expected Hash but got '#{parameters.inspect}'" end unless provider_id.kind_of? Symbol raise "Expected Symbol but got '#{provider_id.inspect}'" end unless h[provider_id].nil? raise "Provider already defined '#{provider_id}'" end h[provider_id] = BitParameters.new parameters end end unless provided_for.nil? unless provided_for.kind_of? Hash raise "Expected Hash but got '#{provided_for.inspect}'" end provided_for.each do |provider_id, reference| unless reference.kind_of? String raise "Expected String but got '#{reference.inspect}'" end unless provider_id.kind_of? Symbol raise "Expected Symbol but got '#{provider_id.inspect}'" end unless h[provider_id].nil? raise "Provider already defined '#{provider_id}'" end h[provider_id] = BitReference.new reference end end h end |
#provided_by(provider_id, params = {}) ⇒ Object
Used inside bit declaration.
136 137 138 |
# File 'lib/bits/bit_declaration.rb', line 136 def provided_by(provider_id, params={}) @provider_data[provider_id] = BitParameters.new params end |
#provided_for(params = {}) ⇒ Object
Used inside bit declaration. Defines that the following set of providers are provided by another bit.
142 143 144 145 146 147 |
# File 'lib/bits/bit_declaration.rb', line 142 def provided_for(params={}) params.each do |key, value| key = key.to_sym @provider_data[key] = BitReference.new value end end |