Module: Cosme

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

Defined Under Namespace

Modules: Helpers Classes: Cosmetic, CosmeticNotFound, Engine, Middleware

Constant Summary collapse

VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.allObject



27
28
29
30
# File 'lib/cosme.rb', line 27

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

.all_for(controller) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/cosme.rb', line 32

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)


44
45
46
# File 'lib/cosme.rb', line 44

def auto_cosmeticize?
  @disable_auto_cosmeticize ? false : true
end

.default_file_path_for(caller_path) ⇒ Object



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

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

.define(cosmetic) ⇒ Object



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

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

  Cosme::Cosmetic.new(cosmetic)
end

.disable_auto_cosmeticize!Object



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

def disable_auto_cosmeticize!
  @disable_auto_cosmeticize = true
end