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.11.3 lib/mls/property.rb
mls-0.11.2 lib/mls/property.rb
mls-0.11.1 lib/mls/property.rb
mls-0.11.0 lib/mls/property.rb
mls-0.9.9 lib/mls/property.rb
mls-0.9.8 lib/mls/property.rb
mls-0.9.6 lib/mls/property.rb
mls-0.9.5 lib/mls/property.rb
mls-0.9.4 lib/mls/property.rb
mls-0.9.3 lib/mls/property.rb
mls-0.9.2 lib/mls/property.rb
mls-0.9.1 lib/mls/property.rb
mls-0.9.0 lib/mls/property.rb
mls-0.8.2 lib/mls/property.rb
mls-0.8.1 lib/mls/property.rb
mls-0.8.0 lib/mls/property.rb
mls-0.7.2 lib/mls/property.rb
mls-0.7.1 lib/mls/property.rb
mls-0.7.0 lib/mls/property.rb
mls-0.6.7 lib/mls/property.rb