Class: Golden::Setting::Resource

Inherits:
Base
  • Object
show all
Defined in:
lib/golden/setting/resource.rb

Class Method Summary collapse

Methods inherited from Base

has_attribute?, method_missing, without_resource

Methods included from FormOption

#field_type, #field_type=, #field_values, #field_values=, #form_options

Methods included from Value

#value, #value=

Class Method Details

.bind(resource) ⇒ Object



7
8
9
10
# File 'lib/golden/setting/resource.rb', line 7

def bind resource
  @resource = resource
  self
end

.first_or_new_object(name, resource = @resource) ⇒ Object



34
35
36
# File 'lib/golden/setting/resource.rb', line 34

def first_or_new_object name, resource = @resource
  named(name, resource).first_or_initialize
end

.named(name, resource = @resource) ⇒ Object



22
23
24
# File 'lib/golden/setting/resource.rb', line 22

def named name, resource = @resource
  with_resource(resource).where(name: name)
end

.new_object(name, resource = @resource) ⇒ Object



30
31
32
# File 'lib/golden/setting/resource.rb', line 30

def new_object name, resource = @resource
  named(name, resource).new
end

.object(name, resource = @resource) ⇒ Object



26
27
28
# File 'lib/golden/setting/resource.rb', line 26

def object name, resource = @resource
  named(name, resource).first
end

.select_object(fields = %w{name value form_options},, resource = @resource) ⇒ Object



38
39
40
# File 'lib/golden/setting/resource.rb', line 38

def select_object fields = %w{name value form_options}, resource = @resource
  with_resource(resource).select(fields)
end

.unbindObject



12
13
14
15
# File 'lib/golden/setting/resource.rb', line 12

def unbind
  @resource = nil
  self
end

.with_resource(resource = @resource) ⇒ Object



17
18
19
20
# File 'lib/golden/setting/resource.rb', line 17

def with_resource resource = @resource
  where(resource_type: resource.class.name).
  where(resource_id: resource.id)
end