Class: Cryptoform::Config::Builder
- Inherits:
-
Object
- Object
- Cryptoform::Config::Builder
- Defined in:
- lib/cryptoform/config/builder.rb
Constant Summary collapse
- PORTS =
1..65_535
- Config =
Data.define(:port, :states)
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(cryptofile) ⇒ Builder
constructor
A new instance of Builder.
- #port(port) ⇒ Object
- #state(name) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(cryptofile) ⇒ Builder
Returns a new instance of Builder.
7 8 9 10 11 12 |
# File 'lib/cryptoform/config/builder.rb', line 7 def initialize(cryptofile) @port = 3000 @states = {} instance_eval(cryptofile) end |
Instance Method Details
#config ⇒ Object
32 33 34 |
# File 'lib/cryptoform/config/builder.rb', line 32 def config Config.new(@port, @states.transform_values(&:config)) end |
#port(port) ⇒ Object
14 15 16 |
# File 'lib/cryptoform/config/builder.rb', line 14 def port(port) @port = port end |
#state(name) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/cryptoform/config/builder.rb', line 18 def state(name, &) name = name.to_sym raise ArgumentError, "state #{name} already configured" if @states.key?(name) @states[name] = Cryptoform::Config::StateConfigBuilder.new(name, &) end |
#validate! ⇒ Object
26 27 28 29 30 |
# File 'lib/cryptoform/config/builder.rb', line 26 def validate! @states.each_value(&:validate!) raise Cryptoform::ConfigValidationError, "at least one state must be configured" if @states.empty? raise Cryptoform::ConfigValidationError, "port must be an in range 0-65545" unless PORTS.include?(@port) end |