Class: HammerBuilder::StringsInjector
- Inherits:
-
Object
- Object
- HammerBuilder::StringsInjector
- Defined in:
- lib/hammer_builder/strings_injector.rb
Instance Attribute Summary collapse
-
#objects_to_update ⇒ Object
readonly
Returns the value of attribute objects_to_update.
-
#strings ⇒ Object
readonly
Returns the value of attribute strings.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(name, value) ⇒ Object
-
#initialize(&block) ⇒ StringsInjector
constructor
A new instance of StringsInjector.
- #inject_to(obj) ⇒ Object
- #replace(name, value) ⇒ Object
Constructor Details
#initialize(&block) ⇒ StringsInjector
Returns a new instance of StringsInjector.
6 7 8 9 10 |
# File 'lib/hammer_builder/strings_injector.rb', line 6 def initialize(&block) @strings = Hash.new {|hash, key| raise ArgumentError "missing key #{key}" } @objects_to_update = [] instance_eval &block end |
Instance Attribute Details
#objects_to_update ⇒ Object (readonly)
Returns the value of attribute objects_to_update.
4 5 6 |
# File 'lib/hammer_builder/strings_injector.rb', line 4 def objects_to_update @objects_to_update end |
#strings ⇒ Object (readonly)
Returns the value of attribute strings.
4 5 6 |
# File 'lib/hammer_builder/strings_injector.rb', line 4 def strings @strings end |
Instance Method Details
#[](name) ⇒ Object
12 13 14 |
# File 'lib/hammer_builder/strings_injector.rb', line 12 def [](name) strings[name] end |
#add(name, value) ⇒ Object
16 17 18 19 20 |
# File 'lib/hammer_builder/strings_injector.rb', line 16 def add(name, value) name = name.to_sym raise "string #{name} is already set to #{value}" if strings.has_key?(name) && self[name] != value replace name, value end |
#inject_to(obj) ⇒ Object
28 29 30 31 |
# File 'lib/hammer_builder/strings_injector.rb', line 28 def inject_to(obj) @objects_to_update << obj strings.keys.each { |name| update_object obj, name } end |
#replace(name, value) ⇒ Object
22 23 24 25 26 |
# File 'lib/hammer_builder/strings_injector.rb', line 22 def replace(name, value) name = name.to_sym strings[name] = value update_objects name end |