snippr 0.15.4 → 0.15.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDg3ZWNjYmM5M2JlMTFmNDAyZDgwMzViZWZiNGQyMThhN2I2ODE1ZA==
4
+ NjA5MWRjNjE2MGU1OWQwY2ExZDViZDBjZjY4ZWU3MzZhNTJjYjU3YQ==
5
5
  data.tar.gz: !binary |-
6
- YjUyZjM5ZjNjNjFiMDY2ZDQ1MmUwYTQzODU2ODg3Mjg3OTc1ZGUyMw==
6
+ MTdiNGRmZjg0ZDliZTQ0Y2UyYTQ3NzE1MGY2NTVmOGQyNDk5M2YyOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjUzOTEwMWM3NzdmZjI5NzM0ZDljOWMwOTMzMWMyZTNiNjg3ODhlODUxYWQ4
10
- NTQ2MDJjNjMzZDJhMzdhMjVjZTY3NjU3MjkyZDdmNDQ2OTQyM2FjMjJlM2E1
11
- N2ZmMWNkMTA4MTk5NmY4NjE5MDYxNjUyZDM4ZDE3ODY1YWE5MDk=
9
+ NzViMTdlZmJkODQ0MTRlYzQ5NjEwMGE0M2Q0YTBjMGJlNGE2NGJhNzZhNjNj
10
+ ZjcyMTgzZTBhYWFlNWYzYWI4ODc0MmY5M2NhMzgxNWRlNTdmNGI2ZmUyNDAy
11
+ N2ZiMzkyOTJjMWMzZDkyZWFhMDNlYTc4ZjViM2NiNjNkMzNhNjQ=
12
12
  data.tar.gz: !binary |-
13
- NjA1NmEyN2YwYzNmZGVhYmYzMWM0YWMzZTljZmQwZDI0MTVmMDJiMjRkYmNl
14
- MWVlMmNmZGJjNDhiOWExZmJiNzlhODg1OWY2NGMzMTVlNzFjNmVkNTdlODFi
15
- ZmY5YWU1NGE1ZWQ3YzgxYzgyMThiZWVhNjEwNTM0ZmQ2ZjUwNWU=
13
+ MzM4MThjNzVmMjE3NmVlOTI0Y2VkM2EwZGFhM2Q3ZThmZGFhMzBiOWFhZGFi
14
+ MjdhYTQ3MjBmZTFmZWM4ZTJmNzJmYjQyMzQzYjM0YTZiNjY0MDEyYTg0Yjc4
15
+ OWQyOTk2NjVjMjYzODYyZTU3ZGJjMTk3YjllMzAwYmVkZjczZmQ=
data/README.md CHANGED
@@ -148,6 +148,11 @@ Same as `valid_from` only the other way round
148
148
  Shows the snippet only in the given environment(s).
149
149
  Separate environments with a comma (eg. production,test,unstable)
150
150
 
151
+ #### on_host
152
+ `on_host: thismachinehostname`:
153
+ Shows the snippet segment only on a host with the name 'thismachinehostname'.
154
+ Multiple hostnames can be given, separated with commas.
155
+
151
156
  ## I18n
152
157
 
153
158
  Snippr comes with support for I18n, but up until further notice, you have to manually enable this
@@ -11,11 +11,13 @@ require 'snippr/path'
11
11
  require 'snippr/processor'
12
12
  require 'snippr/railtie' if defined?(Rails)
13
13
  require 'snippr/view_helper'
14
+ require 'snippr/clock'
14
15
 
15
16
  require 'snippr/segment_parser'
16
17
  require 'snippr/segment_filter/base'
17
18
  require 'snippr/segment_filter/valid_from'
18
19
  require 'snippr/segment_filter/valid_until'
20
+ require 'snippr/segment_filter/on_host'
19
21
  require 'snippr/segment_filter/on_rails_env' if defined?(Rails)
20
22
 
21
23
  require 'snippr/normalizer/camelizer'
@@ -0,0 +1,41 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Snippr
3
+ class Clock
4
+ def self.now
5
+ @interval_sec ||= 0
6
+ Time.now + @interval_sec
7
+ end
8
+
9
+ def self.interval=(interval="0s")
10
+ reset
11
+ @interval_sec = parse(interval)
12
+ end
13
+
14
+ def self.interval
15
+ @interval_sec
16
+ end
17
+
18
+ def self.reset
19
+ @interval_sec = 0
20
+ now
21
+ end
22
+
23
+ private
24
+
25
+ def self.parse(interval)
26
+ return 1 unless interval =~ /[+-][0-9]+[smhd]/
27
+
28
+ multiplicator = case interval[-1]
29
+ when "m" then
30
+ 60
31
+ when "h" then
32
+ 3600
33
+ when "d" then
34
+ 86400
35
+ else
36
+ 1
37
+ end
38
+ @interval_sec = interval[0...-1].to_i*multiplicator
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "socket"
3
+
4
+ module Snippr
5
+ module SegmentFilter
6
+ class OnHost < Base
7
+ def active?
8
+ if in_env?
9
+ true
10
+ else
11
+ false
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def in_env?
18
+ sources.include?(Socket.gethostname)
19
+ end
20
+
21
+ def sources
22
+ @sources ||= @filter_value.split(",").map(&:strip)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,7 +3,7 @@ module Snippr
3
3
  module SegmentFilter
4
4
  class ValidFrom < Base
5
5
  def active?
6
- DateTime.now.to_s >= DateTime.strptime(@filter_value, "%Y-%m-%d %H:%M").to_s
6
+ Snippr::Clock.now.to_s >= DateTime.strptime(@filter_value, "%Y-%m-%d %H:%M").to_s
7
7
  rescue ArgumentError
8
8
  false
9
9
  end
@@ -3,7 +3,7 @@ module Snippr
3
3
  module SegmentFilter
4
4
  class ValidUntil < Base
5
5
  def active?
6
- DateTime.now.to_s <= DateTime.strptime(@filter_value, "%Y-%m-%d %H:%M").to_s
6
+ Snippr::Clock.now.to_s <= DateTime.strptime(@filter_value, "%Y-%m-%d %H:%M").to_s
7
7
  rescue ArgumentError
8
8
  false
9
9
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "snippr"
4
- s.version = "0.15.4"
4
+ s.version = "0.15.7"
5
5
  s.date = Time.now
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Daniel Harrington", "Thomas Jachmann"]
@@ -0,0 +1,77 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ describe "Snippr::Clock" do
5
+
6
+ before do
7
+ Snippr::Clock.reset
8
+ end
9
+
10
+ describe ".now" do
11
+ # use TimeCop here
12
+ it "returns a time object" do
13
+ Snippr::Clock.now.should be_a(Time)
14
+ end
15
+
16
+ it "returns the current time if no interval is given" do
17
+ Snippr::Clock.now.to_i.should == Time.now.to_i
18
+ end
19
+
20
+ it "returns the modified time if an interval is set" do
21
+ Snippr::Clock.interval="+1d"
22
+ Snippr::Clock.now.to_i.should == (Time.now + 86400).to_i
23
+ end
24
+
25
+ end
26
+
27
+ describe ".reset" do
28
+ it "resets the time" do
29
+ Snippr::Clock.interval="+1d"
30
+ Snippr::Clock.reset
31
+ Snippr::Clock.now.to_i.should == Time.now.to_i
32
+ end
33
+ end
34
+
35
+ describe ".interval=" do
36
+ it "sets the time forward" do
37
+ Snippr::Clock.interval="+1m"
38
+ Snippr::Clock.interval.should == +60
39
+ end
40
+
41
+ it "sets the time backward" do
42
+ Snippr::Clock.interval="-1m"
43
+ Snippr::Clock.interval.should == -60
44
+ end
45
+
46
+ it "accepts seconds as scale" do
47
+ Snippr::Clock.interval="+1s"
48
+ Snippr::Clock.interval.should == +1
49
+ end
50
+
51
+ it "accepts minutes as scale" do
52
+ Snippr::Clock.interval="+1m"
53
+ Snippr::Clock.interval.should == +60
54
+ end
55
+
56
+ it "accepts hours as scale" do
57
+ Snippr::Clock.interval="+1h"
58
+ Snippr::Clock.interval.should == +3600
59
+ end
60
+
61
+ it "accepts days as scale" do
62
+ Snippr::Clock.interval="+1d"
63
+ Snippr::Clock.interval.should == +86400
64
+ end
65
+
66
+ it "doesn't set the time if the interval is invalid" do
67
+ Snippr::Clock.interval="blubb"
68
+ Snippr::Clock.interval.should == 1
69
+ end
70
+ end
71
+
72
+ describe "interval" do
73
+ it "returns the interval in seconds" do
74
+ Snippr::Clock.interval.should == 0
75
+ end
76
+ end
77
+ end
@@ -3,6 +3,6 @@ require "spec_helper"
3
3
 
4
4
  describe "Snippr::SegmentFilter::Base" do
5
5
  it "remembers its subclasses" do
6
- Snippr::SegmentFilter::Base.should have(3).filters
6
+ Snippr::SegmentFilter::Base.should have(4).filters
7
7
  end
8
8
  end
@@ -0,0 +1,20 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ describe "Snippr::SegmentFilter::OnHoAst" do
5
+ before do
6
+ Socket.expects(:gethostname).returns("thishost")
7
+ end
8
+
9
+ it "is active on the given host" do
10
+ Snippr::SegmentFilter::OnHost.new("thishost").should be_active
11
+ end
12
+
13
+ it "inactive on other than the given host" do
14
+ Snippr::SegmentFilter::OnHost.new("thathost").should_not be_active
15
+ end
16
+
17
+ it "allows multiple hostnames to be given" do
18
+ Snippr::SegmentFilter::OnHost.new("ahost, , thishost, foobarhost").should be_active
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snippr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.4
4
+ version: 0.15.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-21 00:00:00.000000000 Z
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -121,12 +121,12 @@ files:
121
121
  - .gitignore
122
122
  - .rspec
123
123
  - .travis.yml
124
- - CHANGELOG
125
124
  - Gemfile
126
125
  - LICENSE
127
126
  - README.md
128
127
  - Rakefile
129
128
  - lib/snippr.rb
129
+ - lib/snippr/clock.rb
130
130
  - lib/snippr/i18n.rb
131
131
  - lib/snippr/links.rb
132
132
  - lib/snippr/meta_data.rb
@@ -142,6 +142,7 @@ files:
142
142
  - lib/snippr/processor/wikilinks.rb
143
143
  - lib/snippr/railtie.rb
144
144
  - lib/snippr/segment_filter/base.rb
145
+ - lib/snippr/segment_filter/on_host.rb
145
146
  - lib/snippr/segment_filter/on_rails_env.rb
146
147
  - lib/snippr/segment_filter/valid_from.rb
147
148
  - lib/snippr/segment_filter/valid_until.rb
@@ -167,6 +168,7 @@ files:
167
168
  - spec/fixtures/withBlock.snip
168
169
  - spec/fixtures/withUnderscore/andUnderscore/aSnippet.snip
169
170
  - spec/fixtures/withViewHelperMethod.snip
171
+ - spec/snippr/clock_spec.rb
170
172
  - spec/snippr/i18n_spec.rb
171
173
  - spec/snippr/links_spec.rb
172
174
  - spec/snippr/normalizer/camelizer_spec.rb
@@ -179,6 +181,7 @@ files:
179
181
  - spec/snippr/processor/wikilinks_spec.rb
180
182
  - spec/snippr/processor_spec.rb
181
183
  - spec/snippr/segment_filter/base_spec.rb
184
+ - spec/snippr/segment_filter/on_host_spec.rb
182
185
  - spec/snippr/segment_filter/on_rails_env_spec.rb
183
186
  - spec/snippr/segment_filter/valid_from_spec.rb
184
187
  - spec/snippr/segment_filter/valid_until_spec.rb
@@ -229,6 +232,7 @@ test_files:
229
232
  - spec/fixtures/withBlock.snip
230
233
  - spec/fixtures/withUnderscore/andUnderscore/aSnippet.snip
231
234
  - spec/fixtures/withViewHelperMethod.snip
235
+ - spec/snippr/clock_spec.rb
232
236
  - spec/snippr/i18n_spec.rb
233
237
  - spec/snippr/links_spec.rb
234
238
  - spec/snippr/normalizer/camelizer_spec.rb
@@ -241,6 +245,7 @@ test_files:
241
245
  - spec/snippr/processor/wikilinks_spec.rb
242
246
  - spec/snippr/processor_spec.rb
243
247
  - spec/snippr/segment_filter/base_spec.rb
248
+ - spec/snippr/segment_filter/on_host_spec.rb
244
249
  - spec/snippr/segment_filter/on_rails_env_spec.rb
245
250
  - spec/snippr/segment_filter/valid_from_spec.rb
246
251
  - spec/snippr/segment_filter/valid_until_spec.rb
data/CHANGELOG DELETED
@@ -1,25 +0,0 @@
1
- == 0.3.0 (2010-07-05)
2
- * Added support for links in wiki syntax:
3
-
4
- [[http://www.blaulabs.de|blaulabs]]
5
-
6
- will be converted to:
7
-
8
- <a href="http://www.blaulabs.de">blaulabs</a>
9
-
10
- == 0.2.0 (2010-05-13)
11
- * Added support for I18n snippr files. Simply enable I18n:
12
-
13
- Snippr.i18n = true
14
-
15
- And Snippr will automatically retrieve the current locale from I18n and append
16
- it to every snippr file you're trying to load:
17
-
18
- I18n.locale = :de
19
- Snippr.load(:topup, :success) # Will load: "topup/success_de.snip"
20
-
21
- * From the example above, you should also notice that the method for loading a
22
- snippr file has changed from +new+ to +load+.
23
-
24
- == 0.1.0 (2010-04-30)
25
- * Initial version.