Class: Amp::LighthouseHook
- Defined in:
- lib/amp/extensions/lighthouse.rb
Overview
LighthouseHook
Makes creating lighthouse-committing hooks extremely easy. It is a delegate to Lighthouse (it requires rubygems)
end
end
Instance Attribute Summary collapse
-
#project ⇒ Object
Returns the value of attribute project.
Class Method Summary collapse
-
.add_hook(*events) {|hook| ... } ⇒ Object
Takes a block to configure a hook that can submit changesets to a Lighthouse project.
- .add_hooks(*args, &block) ⇒ Object
-
.make {|hook| ... } ⇒ Proc
Takes a block to configure a hook that can submit changesets to a Lighthouse project.
Instance Method Summary collapse
-
#block ⇒ Proc
Creates a proc that - when executed, with a hook’s options - will send a changeset to Lighthouse.
-
#initialize {|_self| ... } ⇒ LighthouseHook
constructor
Initializes a new LighthouseHook.
Constructor Details
#initialize {|_self| ... } ⇒ LighthouseHook
Initializes a new LighthouseHook. Delegates all unknown methods to the Lighthouse singleton class, yields itself to the (required!) block, and loads the requested project.
97 98 99 100 101 |
# File 'lib/amp/extensions/lighthouse.rb', line 97 def initialize super(Lighthouse) yield self load_project end |
Instance Attribute Details
#project ⇒ Object
Returns the value of attribute project.
91 92 93 |
# File 'lib/amp/extensions/lighthouse.rb', line 91 def project @project end |
Class Method Details
.add_hook(*events) {|hook| ... } ⇒ Object
Takes a block to configure a hook that can submit changesets to a Lighthouse project. The arguments are a list of symbols, which are the events that are automatically hooked into. This provides a terser, though slightly less explicit and less flexible syntax than that used with LighthouseHook.make().
You must provide either a username/password, or an API token to the hook when configuring it. Otherwise, submitting changesets will fail.
75 76 77 78 79 80 81 82 83 |
# File 'lib/amp/extensions/lighthouse.rb', line 75 def self.add_hook(*events, &block) h = self.make(&block) events.each do |evt| Amp::Hook.new(evt) do |opts| h[opts] end end end |
.add_hooks(*args, &block) ⇒ Object
87 88 89 |
# File 'lib/amp/extensions/lighthouse.rb', line 87 def self.add_hooks(*args, &block) add_hook(*args, &block) end |
.make {|hook| ... } ⇒ Proc
Takes a block to configure a hook that can submit changesets to a Lighthouse project. The result is a proc, which when run with an Amp::Hook’s options, will submit the changeset.
You must provide either a username/password, or an API token to the hook when configuring it. Otherwise, submitting changesets will fail.
50 51 52 |
# File 'lib/amp/extensions/lighthouse.rb', line 50 def self.make(&block) new(&block).block end |
Instance Method Details
#block ⇒ Proc
Creates a proc that - when executed, with a hook’s options - will send a changeset to Lighthouse.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/amp/extensions/lighthouse.rb', line 116 def block proc do |opts| cs = Lighthouse::Changeset.new(:project_id => @project.id) ## # Each file must be sent as an array: ["A", file] for an added file, # ["M", file] for a modified file, ["D", file] for a removed file. # Thus, all changes are an array of these arrays, pairing each changed # file with a letter. temp_arr = [] opts[:added].each {|file| temp_arr << ["A", file]} if opts[:added].any? opts[:modified].each {|file| temp_arr << ["M", file]} if opts[:modified].any? opts[:removed].each {|file| temp_arr << ["D", file]} if opts[:removed].any? cs.changes = temp_arr.to_yaml cs.user = opts[:user] cs.updated_at = opts[:date] cs.body = opts[:text] cs.revision = opts[:revision] cs.title = "#{opts[:user]} committed revision #{opts[:revision]}" result = cs.save unless result Amp::UI::err cs.errors.errors.inspect end end end |