Class: Guard::Luca

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/luca.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Luca

Returns a new instance of Luca.



21
22
23
24
25
26
27
28
# File 'lib/guard/luca.rb', line 21

def initialize(watchers=[],options={})
  super
  UI.info "Guard::Luca"
  @faye_notifier = FayeNotifier.new(faye_url)
  @project = ::Luca::Project.find_by_path( Dir.pwd() )

  throw "Could not find a luca project in redis.  Create one for this path." unless @project
end

Instance Attribute Details

#faye_notifierObject

Returns the value of attribute faye_notifier.



19
20
21
# File 'lib/guard/luca.rb', line 19

def faye_notifier
  @faye_notifier
end

#projectObject

Returns the value of attribute project.



19
20
21
# File 'lib/guard/luca.rb', line 19

def project
  @project
end

Instance Method Details

#faye_urlObject



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

def faye_url
  ENV['LUCA_CODE_SYNC_URL'] || "//localhost:9292/faye"
end

#generate_notification_payload_for(paths = []) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/guard/luca.rb', line 34

def generate_notification_payload_for(paths=[])
  paths.compact.inject({}) do |memo,guard_path|
    base = "stylesheets"
    base = "javascripts" if guard_path.match(/(coffee|js|ejs.haml|mustache)$/)
    path = File.join(".","app","assets", base , guard_path)
    memo[path] = project.app.find_asset_wrapper_for(guard_path).to_change_notification
    memo
  end      
end

#run_on_changes(paths) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/guard/luca.rb', line 48

def run_on_changes(paths)
  # temp
  paths.map(&:downcase!)
  notification_payload = generate_notification_payload_for(paths)
  UI.info notification_payload.to_json
  faye_notifier.publish("/changes", notification_payload )
end

#startObject



30
31
32
# File 'lib/guard/luca.rb', line 30

def start
  UI.info "Guard::Luca has been started"
end