Class: UtopiaData::Resource

Inherits:
Object
  • Object
show all
Includes:
Controllers, Models, Naming, Representer
Defined in:
lib/utopia_data/resource.rb,
lib/utopia_data/resource/models.rb,
lib/utopia_data/resource/naming.rb,
lib/utopia_data/resource/controllers.rb,
lib/utopia_data/resource/representer.rb

Defined Under Namespace

Modules: Controllers, Models, Naming, Representer Classes: Name

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Representer

#create_resource_representer

Methods included from Models

#attributes, #columns, #create_resource_model, #model, #model_name, #set

Methods included from Controllers

#controller, #controller_name, #create_resource_controller

Methods included from Naming

#plural_resource_label, #resource_label, #resource_name

Constructor Details

#initialize(resource_name, options = {}, &block) ⇒ Resource

Returns a new instance of Resource.



39
40
41
42
43
44
45
# File 'lib/utopia_data/resource.rb', line 39

def initialize(resource_name, options = {}, &block)
  @config ||= {}
  parse_registration_block(self, &block) if block_given?
  @resource_class_name = "#{resource_name.to_s.classify}"
  @options = options
  create!
end

Instance Attribute Details

#configObject

The configuration to resource



37
38
39
# File 'lib/utopia_data/resource.rb', line 37

def config
  @config
end

#resource_class_nameObject (readonly)

The name of the resource class



35
36
37
# File 'lib/utopia_data/resource.rb', line 35

def resource_class_name
  @resource_class_name
end

Instance Method Details

#resource_classObject

The class this resource wraps. If you register the Post model, Resource#resource_class will point to the Post class



49
50
51
# File 'lib/utopia_data/resource.rb', line 49

def resource_class
  ActiveSupport::Dependencies.constantize(resource_class_name)
end

#resource_table_nameObject



53
54
55
# File 'lib/utopia_data/resource.rb', line 53

def resource_table_name
  resource_class.quoted_table_name
end