Sha256: 237e045f6aedd4c07fff5c505339fd9fbcdc6cc5268a745b3ae946b9050c89aa

Contents?: true

Size: 908 Bytes

Versions: 9

Compression:

Stored size: 908 Bytes

Contents

def attr_limited_regex_accessor(symbol, regex)
    class_eval %{
        def #{symbol}
            @#{symbol}
        end

        def #{symbol}=(new_value)
            if new_value != nil && new_value !~ #{regex}
                raise "invalid #{symbol} format"
            end

            @#{symbol} = new_value
        end
    }
end

def attr_private_limited_regex_accessor(symbol, regex)
    class_eval %{
        def #{symbol}
            @#{symbol}
        end

        private def #{symbol}=(new_value)
            if new_value != nil && new_value !~ #{regex}
                raise "invalid #{symbol} format"
            end

            @#{symbol} = new_value
        end
    }
end

def attr_private_accessor(symbol)
    class_eval %{
        private def #{symbol}
            @#{symbol}
        end

        private def #{symbol}=(new_value)
            @#{symbol} = new_value
        end
    }
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mc_delta-0.4.0 lib/source/attr_limited_regex_accessor.rb
mc_delta-0.3.0 lib/source/attr_limited_regex_accessor.rb
mc_delta-0.2.0 lib/source/attr_limited_regex_accessor.rb
mc_delta-0.1.0 lib/source/attr_limited_regex_accessor.rb
model_gem-0.2.0 lib/model_gem_source/attr_limited_regex_accessor.rb
model_gem-0.1.9 lib/model_gem_source/attr_limited_regex_accessor.rb
model_gem-0.1.8 lib/model_gem_source/attr_limited_regex_accessor.rb
model_gem-0.1.7 ./model_gem_source/attr_limited_regex_accessor.rb
model_gem-0.1.6 ./model_gem_source/attr_limited_regex_accessor.rb