Module: Glass::Config

Defined in:
lib/glass/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.app_nameObject

Returns the value of attribute app_name.



4
5
6
# File 'lib/glass/config.rb', line 4

def app_name
  @app_name
end

.formatObject

Returns the value of attribute format.



6
7
8
# File 'lib/glass/config.rb', line 6

def format
  @format
end

.modelsObject

Returns the value of attribute models.



5
6
7
# File 'lib/glass/config.rb', line 5

def models
  @models
end

.mounted_atObject

Returns the value of attribute mounted_at.



7
8
9
# File 'lib/glass/config.rb', line 7

def mounted_at
  @mounted_at
end

.registryObject

Returns the value of attribute registry.



9
10
11
# File 'lib/glass/config.rb', line 9

def registry
  @registry
end

.routesObject

Returns the value of attribute routes.



8
9
10
# File 'lib/glass/config.rb', line 8

def routes
  @routes
end

Class Method Details

.capitalize_singularize(model) ⇒ Object



29
30
31
# File 'lib/glass/config.rb', line 29

def capitalize_singularize(model)
  model.capitalize.singularize
end

.create_routes(model) ⇒ Object



33
34
35
36
37
38
# File 'lib/glass/config.rb', line 33

def create_routes(model)
  model_scope = pluralize_downcase(model)
  model_name = capitalize_singularize(model)

  return_routes(model_name, model_scope)
end

.models_with_routesObject



19
20
21
22
23
# File 'lib/glass/config.rb', line 19

def models_with_routes
  @models.each do |model|
    @routes[model.downcase.to_sym] = create_routes(model)
  end
end

.pluralize_downcase(model) ⇒ Object



25
26
27
# File 'lib/glass/config.rb', line 25

def pluralize_downcase(model)
  model.pluralize.downcase
end

.resetObject



11
12
13
14
15
16
17
# File 'lib/glass/config.rb', line 11

def reset
  @app_name = ''
  @mounted_at = '/api'
  @models = []
  @format = :json
  @routes = {}
end

.return_routes(model_name, model_scope) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/glass/config.rb', line 40

def return_routes(model_name, model_scope)
  return {
      "index"   => { "type" => "get",   "path" => "/#{model_scope}"      },
      "show"    => { "type" => "get",   "path" => "/#{model_scope}/:id"  },
      "create"  => { "type" => "post",  "path" => "/#{model_scope}"      },
      "update"  => { "type" => "put",   "path" => "/#{model_scope}/:id"  },
      "destroy" => { "type" => "delete","path" => "/#{model_scope}/:id"  } }
end

.setupObject



49
50
51
# File 'lib/glass/config.rb', line 49

def setup
  models_with_routes
end