Sha256: f6c7a31808916f3757af62531e6f4eea91820107207dc9f9d650fcc7aa36c47b

Contents?: true

Size: 1.06 KB

Versions: 105

Compression:

Stored size: 1.06 KB

Contents

class MLS::Property
	DEFAULT_OPTIONS = { :serialize => :always	}
	
	attr_reader :model, :name, :instance_variable_name, :options, :default
	attr_reader :reader_visibility, :writer_visibility

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

		set_default_value
		determine_visibility
	end

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

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

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

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

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

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

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
mls-0.2.21 lib/mls/property.rb
mls-0.2.20 lib/mls/property.rb
mls-0.2.19 lib/mls/property.rb
mls-0.2.18 lib/mls/property.rb
mls-0.2.17 lib/mls/property.rb
mls-0.2.16 lib/mls/property.rb
mls-0.2.15 lib/mls/property.rb
mls-0.2.14 lib/mls/property.rb
mls-0.2.13 lib/mls/property.rb
mls-0.2.12 lib/mls/property.rb
mls-0.2.11 lib/mls/property.rb
mls-0.2.9.1 lib/mls/property.rb
mls-0.2.10 lib/mls/property.rb
mls-0.2.9 lib/mls/property.rb
mls-0.2.8.2 lib/mls/property.rb
mls-0.2.8.1 lib/mls/property.rb
mls-0.2.8 lib/mls/property.rb
mls-0.2.7 lib/mls/property.rb
mls-0.2.6 lib/mls/property.rb
mls-0.2.5 lib/mls/property.rb