module Opto::Model::AttributeDeclaration::ClassMethods
Public Instance Methods
attribute(name, type, arguments = {})
click to toggle source
# File lib/opto/model/attribute_declaration.rb, line 14 def attribute(name, type, arguments = {}) if attribute_definitions.find { |d| d[:name] == name } raise RuntimeError, "Duplicate attribute '#{name}'" end if type.to_sym == :boolean arguments.merge!(as: "boolean") end attribute_definitions << arguments.merge(name: name, type: type) define_method "#{name}_handler" do collection[name].handler end if type.to_sym == :boolean define_method "#{name}?" do collection[name].value end end define_method name do collection[name].value end define_method "#{name}=" do |value| collection[name].set(value) end end
attribute_definitions()
click to toggle source
# File lib/opto/model/attribute_declaration.rb, line 10 def attribute_definitions @attribute_definitions ||= [] end