Module: Hammock::ModelAttributes::ClassMethods

Defined in:
lib/hammock/model_attributes.rb

Instance Method Summary collapse

Instance Method Details

#accessible_attributes_on_createObject



40
41
42
# File 'lib/hammock/model_attributes.rb', line 40

def accessible_attributes_on_create
  read_inheritable_attribute :attr_accessible_on_create
end

#accessible_attributes_on_updateObject



43
44
45
# File 'lib/hammock/model_attributes.rb', line 43

def accessible_attributes_on_update
  read_inheritable_attribute :attr_accessible_on_update
end

#attr_accessible_on_create(*attributes) ⇒ Object



24
25
26
# File 'lib/hammock/model_attributes.rb', line 24

def attr_accessible_on_create *attributes
  write_inheritable_attribute :attr_accessible_on_create, Set.new(attributes.map(&:to_s)) + (accessible_attributes_on_create || [])
end

#attr_accessible_on_update(*attributes) ⇒ Object



27
28
29
# File 'lib/hammock/model_attributes.rb', line 27

def attr_accessible_on_update *attributes
  write_inheritable_attribute :attr_accessible_on_update, Set.new(attributes.map(&:to_s)) + (accessible_attributes_on_update || [])
end

#default_attributesObject



37
38
39
# File 'lib/hammock/model_attributes.rb', line 37

def default_attributes
  read_inheritable_attribute(:default_attributes) || {}
end

#has_defaults(attrs) ⇒ Object



21
22
23
# File 'lib/hammock/model_attributes.rb', line 21

def has_defaults attrs
  write_inheritable_attribute :default_attributes, (default_attributes || {}).merge(attrs)
end

#nest_within(*attributes) ⇒ Object



18
19
20
# File 'lib/hammock/model_attributes.rb', line 18

def nest_within *attributes
  write_inheritable_attribute :nestable_routing_resources, attributes
end

#nestable_routing_resourcesObject



34
35
36
# File 'lib/hammock/model_attributes.rb', line 34

def nestable_routing_resources
  read_inheritable_attribute(:nestable_routing_resources)
end

#route_by(attribute) ⇒ Object



12
13
14
15
16
17
# File 'lib/hammock/model_attributes.rb', line 12

def route_by attribute
  write_inheritable_attribute :routing_attribute, attribute.to_sym
  define_method :to_param do
    send self.class.routing_attribute
  end
end

#routing_attributeObject



31
32
33
# File 'lib/hammock/model_attributes.rb', line 31

def routing_attribute
  read_inheritable_attribute(:routing_attribute) || :id
end