Class: MLS::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/mls/property.rb

Direct Known Subclasses

Array, Boolean, DateTime, Decimal, Fixnum, Hash, String

Defined Under Namespace

Classes: Array, Boolean, DateTime, Decimal, Fixnum, Hash, String

Constant Summary collapse

DEFAULT_OPTIONS =
{ :serialize => :always	}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Property

Returns a new instance of Property.



7
8
9
10
11
12
13
14
# File 'lib/mls/property.rb', line 7

def initialize(name, options={})
	@name                   = name
	@instance_variable_name = "@#{@name}".freeze
	@options                = DEFAULT_OPTIONS.merge(options)

	set_default_value
	determine_visibility
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



4
5
6
# File 'lib/mls/property.rb', line 4

def default
  @default
end

#instance_variable_nameObject (readonly)

Returns the value of attribute instance_variable_name.



4
5
6
# File 'lib/mls/property.rb', line 4

def instance_variable_name
  @instance_variable_name
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/mls/property.rb', line 4

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/mls/property.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/mls/property.rb', line 4

def options
  @options
end

#reader_visibilityObject (readonly)

Returns the value of attribute reader_visibility.



5
6
7
# File 'lib/mls/property.rb', line 5

def reader_visibility
  @reader_visibility
end

#writer_visibilityObject (readonly)

Returns the value of attribute writer_visibility.



5
6
7
# File 'lib/mls/property.rb', line 5

def writer_visibility
  @writer_visibility
end

Class Method Details

.demodulized_namesObject



34
35
36
# File 'lib/mls/property.rb', line 34

def self.demodulized_names
	@demodulized_names ||= {}
end

.determine_class(type) ⇒ Object



25
26
27
28
# File 'lib/mls/property.rb', line 25

def self.determine_class(type)
	return type if type < MLS::Property
	find_class(::ActiveSupport::Inflector.demodulize(type))
end

.find_class(name) ⇒ Object



38
39
40
41
42
# File 'lib/mls/property.rb', line 38

def self.find_class(name)
	klass   = demodulized_names[name]
	klass ||= const_get(name) if const_defined?(name)
	klass
end

.inherited(descendant) ⇒ Object



30
31
32
# File 'lib/mls/property.rb', line 30

def self.inherited(descendant)
	demodulized_names[::ActiveSupport::Inflector.demodulize(descendant.name)] ||= descendant
end

Instance Method Details

#determine_visibilityObject

default :public



20
21
22
23
# File 'lib/mls/property.rb', line 20

def determine_visibility # default :public
	@reader_visibility = @options[:reader] || :public
	@writer_visibility = @options[:writer] || :public
end

#set_default_valueObject



16
17
18
# File 'lib/mls/property.rb', line 16

def set_default_value
	@default = @options[:default]
end