Module: Mattock::Configurable

Extended by:
ClassMethods
Included in:
CascadingDefinition, Struct
Defined in:
lib/mattock/configurable.rb

Defined Under Namespace

Modules: ClassMethods Classes: Struct

Constant Summary

RequiredField =
Object.new

Instance Method Summary (collapse)

Methods included from ClassMethods

copy_settings, default_values, included, missing_required_fields_on, nested, set_defaults_on

Instance Method Details

- (Object) check_required



122
123
124
125
126
127
128
# File 'lib/mattock/configurable.rb', line 122

def check_required
  missing = self.class.missing_required_fields_on(self)
  unless missing.empty?
    raise "Required field#{missing.length > 1 ? "s" : ""} #{missing.map{|field| field.to_s.inspect}.join(", ")} unset on #{self.inspect}"
  end
  self
end

- (Object) copy_settings_to(other)



112
113
114
115
# File 'lib/mattock/configurable.rb', line 112

def copy_settings_to(other)
  self.class.copy_settings(self, other)
  self
end

- (Object) nil_fields(*names) Also known as: nil_field



152
153
154
155
# File 'lib/mattock/configurable.rb', line 152

def nil_fields(*names)
  self.class.nil_fields(*names)
  self
end

- (Object) required_fields(*names) Also known as: required_field



146
147
148
149
# File 'lib/mattock/configurable.rb', line 146

def required_fields(*names)
  self.class.required_fields(*names)
  self
end

- (Object) setting(name, default_value = nil)



134
135
136
137
# File 'lib/mattock/configurable.rb', line 134

def setting(name, default_value = nil)
  self.class.setting(name, default_value)
  instance_variable_set("@#{name}", default_value)
end

- (Object) settings(hash)



139
140
141
142
143
144
# File 'lib/mattock/configurable.rb', line 139

def settings(hash)
  hash.each_pair do |name, value|
    setting(name, value)
  end
  return self
end

- (Object) setup_defaults



117
118
119
120
# File 'lib/mattock/configurable.rb', line 117

def setup_defaults
  self.class.set_defaults_on(self)
  self
end

- (Boolean) unset?(value)

Returns:

  • (Boolean)


130
131
132
# File 'lib/mattock/configurable.rb', line 130

def unset?(value)
  value == RequiredField
end