Module: Cosme

Defined in:
lib/cosme.rb,
lib/cosme/engine.rb,
lib/cosme/helpers.rb,
lib/cosme/version.rb,
lib/cosme/middleware.rb

Defined Under Namespace

Modules: Helpers Classes: Engine, Middleware

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.allObject



24
25
26
27
# File 'lib/cosme.rb', line 24

def all
  return [] unless @cosmetics
  @cosmetics.values
end

.all_for(controller) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/cosme.rb', line 29

def all_for(controller)
  return all if controller.blank?

  all.select do |cosmetic|
    routes_match?(controller, cosmetic[:routes])
  end
end

.auto_cosmeticize?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/cosme.rb', line 41

def auto_cosmeticize?
  @disable_auto_cosmeticize ? false : true
end

.default_file_path_for(caller_path) ⇒ Object



20
21
22
# File 'lib/cosme.rb', line 20

def default_file_path_for(caller_path)
  File.join(File.dirname(caller_path), File.basename(caller_path, '.*'))
end

.define(cosmetic) ⇒ Object



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

def define(cosmetic)
  caller_path = caller_locations(1, 1)[0].path

  cosmetic[:render] = { file: default_file_path_for(caller_path) } unless cosmetic[:render]

  @cosmetics ||= {}
  @cosmetics[caller_path] = cosmetic
end

.disable_auto_cosmeticize!Object



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

def disable_auto_cosmeticize!
  @disable_auto_cosmeticize = true
end