safety_pin 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/bin/safety-pin ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ options = {}
5
+ option_parser = OptionParser.new do |opts|
6
+ opts.banner = "Usage: #{File.basename(__FILE__)} [-h HOST | -d]"
7
+
8
+ opts.on("-h", "--host HOST", "JCR host (e.g., http://localhost:4502)") do |host|
9
+ options[:host] = host
10
+ end
11
+
12
+ opts.on("-d", "Developer mode -- connects to http://admin:admin@localhost:4502") do |developer_mode|
13
+ options[:developer_mode] = !!developer_mode
14
+ end
15
+
16
+ opts.on_tail("--help", "Show this message") do
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+ option_parser.parse!
23
+
24
+ unless options[:host] || options[:developer_mode]
25
+ puts option_parser
26
+ exit 1
27
+ end
28
+
29
+ if options[:developer_mode]
30
+ host = "http://localhost:4502"
31
+ username = "admin"
32
+ password = "cq4me"
33
+ else
34
+ host = options.fetch(:host)
35
+ print "Username: "
36
+ username = gets.chomp
37
+ print "Password: "
38
+ password = gets.chomp
39
+ end
40
+
41
+ ENV["HOST"] = host
42
+ ENV["USERNAME"] = username
43
+ ENV["PASSWORD"] = password
44
+
45
+ exec "irb -r './console_loader' --simple-prompt"
data/console_loader.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  $:<<File.dirname(__FILE__)
2
2
  require 'lib/safety_pin'
3
+
3
4
  include SafetyPin
4
- JCR.dev_login
5
+
6
+ puts "Connecting to #{ENV["HOST"]}"
7
+ JCR.login(hostname: ENV["HOST"], username: ENV["USERNAME"], password: ENV["PASSWORD"])
@@ -359,6 +359,27 @@ module SafetyPin
359
359
 
360
360
  NodeBlueprint.new(:path => path.to_s, :properties => properties, :primary_type => primary_type)
361
361
  end
362
+
363
+ def replace_property(opts)
364
+ opts = {recursive: false}.merge(opts)
365
+ name = opts.fetch(:name)
366
+ target = opts.fetch(:target)
367
+ replacement = opts.fetch(:replacement)
368
+
369
+ modified_nodes = []
370
+ if has_property(name) and self[name].match(target)
371
+ self[name] = replacement
372
+ modified_nodes << self
373
+ end
374
+
375
+ modified_nodes << children.map {|child_node| child_node.replace_property(opts) } if opts.fetch(:recursive)
376
+
377
+ modified_nodes.flatten
378
+ end
379
+
380
+ def has_property(name)
381
+ properties.keys.include?(name)
382
+ end
362
383
  end
363
384
 
364
385
  class NodeError < Exception; end
@@ -1,3 +1,3 @@
1
1
  module SafetyPin
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safety_pin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,13 +9,13 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-13 00:00:00.000000000 Z
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: An easy-to-use JCR connector for JRuby
15
15
  email:
16
16
  - jnraine@gmail.com
17
17
  executables:
18
- - console
18
+ - safety-pin
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
@@ -26,7 +26,7 @@ files:
26
26
  - LICENSE
27
27
  - README.md
28
28
  - Rakefile
29
- - bin/console
29
+ - bin/safety-pin
30
30
  - console_loader.rb
31
31
  - lib/safety_pin.rb
32
32
  - lib/safety_pin/jcr.rb
@@ -75,3 +75,4 @@ test_files:
75
75
  - spec/query_spec.rb
76
76
  - spec/spec_helper.rb
77
77
  - spec/where_condition_spec.rb
78
+ has_rdoc:
data/bin/console DELETED
@@ -1 +0,0 @@
1
- irb -r './console_loader' --simple-prompt