diff options
| author | Randy Morgan <[email protected]> | 2012-10-09 21:50:25 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-09 21:50:25 +0900 |
| commit | be95b7eaa72cd7007bc0fef22d0c3ea4fa3c3553 (patch) | |
| tree | 4553f0ec8767385961e08162ebfa65eb96c77420 /lib/axlsx/util | |
| parent | f0bc5f17ddafd8172646a04bbbc0d3b958c0205f (diff) | |
| download | caxlsx-be95b7eaa72cd7007bc0fef22d0c3ea4fa3c3553.tar.gz caxlsx-be95b7eaa72cd7007bc0fef22d0c3ea4fa3c3553.zip | |
extracted accessor methods into module that is scope because polluting Module or Class is just not cool
Diffstat (limited to 'lib/axlsx/util')
| -rw-r--r-- | lib/axlsx/util/accessors.rb | 26 | ||||
| -rw-r--r-- | lib/axlsx/util/module.rb | 18 |
2 files changed, 26 insertions, 18 deletions
diff --git a/lib/axlsx/util/accessors.rb b/lib/axlsx/util/accessors.rb new file mode 100644 index 00000000..3096d9c7 --- /dev/null +++ b/lib/axlsx/util/accessors.rb @@ -0,0 +1,26 @@ +module Axlsx + module Accessors + def self.included(base) + base.send :extend, ClassMethods + end + + module ClassMethods + def string_attr_accessor(*symbols) + validated_attr_accessor(symbols, 'validate_string') + end + + def boolean_attr_accessor(*symbols) + validated_attr_accessor(symbols, 'validate_boolean') + end + + SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end" + def validated_attr_accessor(symbols, validator) + symbols.each do |symbol| + attr_reader symbol + module_eval(SETTER % [symbol.to_s, validator, symbol.to_s], __FILE__, __LINE__) + end + end + end + end +end + diff --git a/lib/axlsx/util/module.rb b/lib/axlsx/util/module.rb deleted file mode 100644 index 4f3543a0..00000000 --- a/lib/axlsx/util/module.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Module - def string_attr_accessor(*symbols) - validated_attr_accessor(symbols, 'validate_string') - end - - def boolean_attr_accessor(*symbols) - validated_attr_accessor(symbols, 'validate_boolean') - end - - SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end" - def validated_attr_accessor(symbols, validator) - symbols.each do |symbol| - attr_reader symbol - module_eval(SETTER % [symbol.to_s, validator, symbol.to_s], __FILE__, __LINE__) - end - end - -end |
