Module: Zen::Service::Plugins::Attributes::ClassMethods

Defined in:
lib/zen/service/plugins/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute_methodsObject



65
66
67
# File 'lib/zen/service/plugins/attributes.rb', line 65

def attribute_methods
  const_get(:AttributeMethods)
end

#attributes(*attrs) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/zen/service/plugins/attributes.rb', line 69

def attributes(*attrs)
  attributes_list.concat(attrs)

  attrs.each do |name|
    attribute_methods.send(:define_method, name) { @attributes[name] }
    attribute_methods.send(:define_method, "#{name}?") { !!@attributes[name] }
  end
end

#attributes_listObject



78
79
80
# File 'lib/zen/service/plugins/attributes.rb', line 78

def attributes_list
  @attributes_list ||= []
end

#from(service) ⇒ Object



82
83
84
# File 'lib/zen/service/plugins/attributes.rb', line 82

def from(service)
  new(service.send(:attributes))
end

#inherited(service_class) ⇒ Object



58
59
60
61
62
63
# File 'lib/zen/service/plugins/attributes.rb', line 58

def inherited(service_class)
  service_class.const_set(:AttributeMethods, Module.new)
  service_class.send(:include, service_class::AttributeMethods)
  service_class.attributes_list.replace attributes_list.dup
  super
end