Class: AdaptiveConfiguration::PropertiesBuilder
- Inherits:
-
Object
- Object
- AdaptiveConfiguration::PropertiesBuilder
- Defined in:
- lib/adaptive_configuration/properties_builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
Instance Method Summary collapse
-
#initialize(&block) ⇒ PropertiesBuilder
constructor
A new instance of PropertiesBuilder.
- #parameter(name, *args) ⇒ Object
- #parameters(name, options = {}, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ PropertiesBuilder
Returns a new instance of PropertiesBuilder.
8 9 10 11 |
# File 'lib/adaptive_configuration/properties_builder.rb', line 8 def initialize( &block ) @definitions = {} self.instance_eval( &block ) if block_given? end |
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
6 7 8 |
# File 'lib/adaptive_configuration/properties_builder.rb', line 6 def definitions @definitions end |
Instance Method Details
#parameter(name, *args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/adaptive_configuration/properties_builder.rb', line 13 def parameter( name, *args ) name = name.to_sym = nil raise NameError, "The name '#{name}' is reserved and cannot be used for parameters." \ if AdaptiveConfiguration::Scaffold.instance_methods.include?( name ) if args.first.is_a?( ::Hash ) # when called without type: parameter :stream, as: :streams = args.first else # when called with type: parameter :stream, Boolean, as: :streams = args[ 1 ] || {} [ :type ] = args.first end validate_in!( name, [ :type ], [ :in ] ) if [ :in ] @definitions[ name ] = end |
#parameters(name, options = {}, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/adaptive_configuration/properties_builder.rb', line 34 def parameters( name, = {}, &block ) raise NameError, "The name '#{name}' is reserved and cannot be used for parameters." \ if AdaptiveConfiguration::Scaffold.instance_methods.include?( name ) builder = PropertiesBuilder.new builder.instance_eval( &block ) if block @definitions[ name ] = .merge( { type: Object, definitions: builder.definitions } ) end |