lib/abstract_mapper/settings.rb in abstract_mapper-0.0.2 vs lib/abstract_mapper/settings.rb in abstract_mapper-0.1.0
- old
+ new
@@ -34,60 +34,52 @@
#
# @return [Class] The builder class with domain-specific commands
#
attr_reader :builder
- # @!scope class
- # @!method new(&block)
- # Creates a domain-specific settings with commands and rules initialized
- # from inside a block
+ # Initializes a domain-specific settings with commands and rules
+ # being set in the block.
#
# @param [Proc] block
#
- # @return [AbstractMapper::Settings]
-
- # @private
- def initialize(&block)
- __set_rules__
- __set_commands__
- __configure__(&block)
- __set_builder__
- __set_optimizer__
+ # @yield the block with settings for commands and rules
+ #
+ def initialize(rules = Rules.new, commands = Commands.new, &block)
+ @rules = rules
+ @commands = commands
+ configure(&block)
IceNine.deep_freeze(self)
end
+ # Returns a new class with rules and commands added from the block
+ # to the existing ones
+ #
+ # @return [AbstractMapper::Settings]
+ #
+ # @yield the block with settings for commands and rules
+ #
+ def update(&block)
+ self.class.new(rules, commands, &block)
+ end
+
private
def rule(value)
- fn = Functions[:subclass?, Rule]
+ fn = Functions[:subclass?, Rules::Base]
fail Errors::WrongRule.new(value) unless fn[value]
@rules = rules << value
end
def command(name, node, &block)
- fn = Functions[:subclass?, Node]
+ fn = Functions[:subclass?, AST::Node]
fail Errors::WrongNode.new(node) unless fn[node]
@commands = commands << [name, node, block]
end
- def __set_rules__
- @rules = Rules.new
- end
-
- def __set_commands__
- @commands = Commands.new
- end
-
- def __configure__(&block)
+ def configure(&block)
instance_eval(&block) if block_given?
- end
-
- def __set_builder__
@builder = Class.new(Builder)
builder.commands = commands
- end
-
- def __set_optimizer__
@optimizer = Optimizer.new(rules)
end
end # class Settings