Sha256: f1fe8f2632033ca44aff66c6866d3f0e69d76091db953e7a7da5fed2750564e0

Contents?: true

Size: 492 Bytes

Versions: 5

Compression:

Stored size: 492 Bytes

Contents

class InvalidValue < StandardError
end

def greater_than(base_value)
  lambda { |val| val > base_value }
end


def casting_attr_accessor(accessor, type, *validators)

  define_method(accessor) do
    instance_variable_get("@#{accessor}")
  end

  define_method("#{accessor}=") do |val|
    new_val = Kernel.send(type.to_s, val)
    if validators and ! validators.all? {|v| v.call(new_val) }
      raise InvalidValue, val
    end

    instance_variable_set("@#{accessor}", new_val)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vagrant-openstack-cloud-provider-1.1.13 lib/vagrant-openstack-cloud-provider/utils.rb
vagrant-openstack-cloud-provider-1.1.12 lib/vagrant-openstack-cloud-provider/utils.rb
vagrant-openstack-cloud-provider-1.1.11 lib/vagrant-openstack-cloud-provider/utils.rb
vagrant-openstack-cloud-provider-1.1.10 lib/vagrant-openstack-cloud-provider/utils.rb
vagrant-openstack-cloud-provider-1.1.9 lib/vagrant-openstack-cloud-provider/utils.rb