Class: MLS::Property
- Inherits:
-
Object
- Object
- MLS::Property
- Defined in:
- lib/mls/property.rb
Defined Under Namespace
Classes: Array, Boolean, DateTime, Decimal, Fixnum, Hash, String
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :serialize => :always }
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#instance_variable_name ⇒ Object
readonly
Returns the value of attribute instance_variable_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#reader_visibility ⇒ Object
readonly
Returns the value of attribute reader_visibility.
-
#writer_visibility ⇒ Object
readonly
Returns the value of attribute writer_visibility.
Class Method Summary collapse
- .demodulized_names ⇒ Object
- .determine_class(type) ⇒ Object
- .find_class(name) ⇒ Object
- .inherited(descendant) ⇒ Object
Instance Method Summary collapse
-
#determine_visibility ⇒ Object
default :public.
-
#initialize(name, options = {}) ⇒ Property
constructor
A new instance of Property.
- #set_default_value ⇒ Object
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, ={}) @name = name @instance_variable_name = "@#{@name}".freeze @options = DEFAULT_OPTIONS.merge() set_default_value determine_visibility end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'lib/mls/property.rb', line 4 def default @default end |
#instance_variable_name ⇒ Object (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 |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/mls/property.rb', line 4 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/mls/property.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/mls/property.rb', line 4 def @options end |
#reader_visibility ⇒ Object (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_visibility ⇒ Object (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_names ⇒ Object
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_visibility ⇒ Object
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_value ⇒ Object
16 17 18 |
# File 'lib/mls/property.rb', line 16 def set_default_value @default = @options[:default] end |