alephant 0.0.9.9.1-java → 0.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/alephant.gemspec +8 -2
  4. data/lib/alephant.rb +40 -56
  5. data/lib/alephant/models/jsonpath_lookup.rb +16 -0
  6. data/lib/alephant/models/parser.rb +20 -2
  7. data/lib/alephant/models/queue.rb +6 -5
  8. data/lib/alephant/models/render_mapper.rb +56 -0
  9. data/lib/alephant/models/writer.rb +44 -0
  10. data/lib/alephant/version.rb +1 -1
  11. data/lib/env.rb +0 -2
  12. data/spec/alephant_spec.rb +51 -197
  13. data/spec/fixtures/components/foo/models/bar.rb +7 -0
  14. data/spec/fixtures/components/foo/models/foo.rb +1 -1
  15. data/spec/parser_spec.rb +17 -9
  16. data/spec/render_mapper_spec.rb +63 -0
  17. data/spec/spec_helper.rb +1 -0
  18. data/spec/writer_spec.rb +52 -0
  19. metadata +97 -34
  20. data/bin/alephant +0 -37
  21. data/lib/alephant/errors.rb +0 -6
  22. data/lib/alephant/errors/invalid_view_path.rb +0 -6
  23. data/lib/alephant/errors/view_model_not_found.rb +0 -6
  24. data/lib/alephant/errors/view_template_not_found.rb +0 -6
  25. data/lib/alephant/models/cache.rb +0 -28
  26. data/lib/alephant/models/logger.rb +0 -22
  27. data/lib/alephant/models/multi_renderer.rb +0 -84
  28. data/lib/alephant/models/renderer.rb +0 -34
  29. data/lib/alephant/models/sequence_table.rb +0 -99
  30. data/lib/alephant/models/sequencer.rb +0 -61
  31. data/lib/alephant/preview/server.rb +0 -75
  32. data/lib/alephant/preview/template.rb +0 -63
  33. data/lib/alephant/tasks.rb +0 -8
  34. data/lib/alephant/util/string.rb +0 -9
  35. data/lib/alephant/views.rb +0 -15
  36. data/lib/alephant/views/base.rb +0 -16
  37. data/lib/alephant/views/preview.rb +0 -44
  38. data/lib/tasks/preview.rake +0 -16
  39. data/spec/cache_spec.rb +0 -63
  40. data/spec/logger_spec.rb +0 -40
  41. data/spec/multi_renderer_spec.rb +0 -92
  42. data/spec/renderer_spec.rb +0 -62
  43. data/spec/sequencer_spec.rb +0 -107
@@ -1,8 +0,0 @@
1
- require 'rake'
2
- require 'pathname'
3
-
4
- root = Pathname.new(__FILE__).dirname.parent
5
- task_path = (root + 'tasks').realdirpath
6
-
7
- Dir["#{task_path}/**/*.rake"].each { |ext| load ext } if defined?(Rake)
8
-
@@ -1,9 +0,0 @@
1
- class String
2
- def underscore
3
- self.gsub(/::/, '/').
4
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
- tr("-", "_").
7
- downcase
8
- end
9
- end
@@ -1,15 +0,0 @@
1
- require 'alephant/views/base'
2
-
3
- module Alephant::Views
4
- @@views = {}
5
-
6
- def self.register(klass)
7
- id = klass.name.split('::').last
8
- @@views[id.underscore] = klass
9
- end
10
-
11
- def self.get_registered_class(id)
12
- @@views[id]
13
- end
14
- end
15
-
@@ -1,16 +0,0 @@
1
- require 'mustache'
2
-
3
- module Alephant::Views
4
- class Base < Mustache
5
- attr_accessor :data
6
-
7
- def initialize(data)
8
- @data = data
9
- end
10
-
11
- def self.inherited(subclass)
12
- ::Alephant::Views.register(subclass)
13
- end
14
- end
15
- end
16
-
@@ -1,44 +0,0 @@
1
- require 'alephant/views/base'
2
-
3
- module Alephant
4
- module Views
5
- class Preview < Mustache
6
- attr_accessor :regions
7
-
8
- def initialize(regions, template_location)
9
- @regions=regions
10
- self.template_file = template_location
11
- end
12
-
13
- def static_host
14
- ENV['STATIC_HOST'] || 'localhost:8000'
15
- end
16
-
17
- def method_missing(name, *args, &block)
18
- return super unless respond_to? name.to_s
19
- region @regions[name.to_s]
20
- end
21
-
22
- def respond_to?(method)
23
- valid_regions.include? method.to_s
24
- end
25
-
26
- def region(components)
27
- if components.kind_of?(Array)
28
- components.join
29
- else
30
- components
31
- end
32
- end
33
-
34
- def valid_regions
35
- self.template.tokens.find_all { |token|
36
- token.is_a?(Array) && token[0] == :mustache
37
- }.map{ |token|
38
- token[2][2][0].to_s
39
- }
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,16 +0,0 @@
1
- require 'alephant/preview/server'
2
- require 'alephant/preview/template'
3
-
4
- namespace :alephant do
5
- namespace :preview do
6
- task :go do
7
- Alephant::Preview::Server.run!
8
- end
9
- task :update do
10
- Alephant::Preview::Template.update(
11
- "#{::Alephant::Preview.path}/templates/preview.mustache"
12
- )
13
- end
14
- end
15
- end
16
-
data/spec/cache_spec.rb DELETED
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
- require 'pry'
3
-
4
- describe Alephant::Cache do
5
- let(:id) { :id }
6
- let(:path) { :path }
7
- let(:data) { :data }
8
- subject { Alephant::Cache }
9
-
10
- describe "initialize(id, path)" do
11
- it "sets and exposes id, path instance variables " do
12
- instance = subject.new(id, path)
13
- expect(instance.id).to eq(id)
14
- expect(instance.path).to eq(path)
15
- end
16
-
17
- it "sets bucket instance variable as S3 bucket with id" do
18
- instance = subject.new(id, path)
19
-
20
- expect(instance.bucket).to be_an AWS::S3::Bucket
21
- expect(instance.bucket.name).to eq('id')
22
- end
23
- end
24
-
25
- describe "put(id, data)" do
26
- it "sets bucket path/id content data" do
27
- s3_object_collection = double()
28
- s3_object_collection.should_receive(:write).with(:data)
29
-
30
- s3_bucket = double()
31
- s3_bucket.should_receive(:objects).and_return(
32
- {
33
- "path/id" => s3_object_collection
34
- }
35
- )
36
-
37
- AWS::S3.any_instance.stub(:buckets).and_return({ id => s3_bucket })
38
- instance = subject.new(id, path)
39
-
40
- instance.put(id, data);
41
- end
42
- end
43
-
44
- describe "get(id)" do
45
- it "gets bucket path/id content data" do
46
- s3_object_collection = double()
47
- s3_object_collection.should_receive(:read)
48
-
49
- s3_bucket = double()
50
- s3_bucket.should_receive(:objects).and_return(
51
- {
52
- "path/id" => s3_object_collection
53
- }
54
- )
55
-
56
- AWS::S3.any_instance.stub(:buckets).and_return({ id => s3_bucket })
57
-
58
- instance = subject.new(id, path)
59
- instance.get(id);
60
- end
61
- end
62
- end
63
-
data/spec/logger_spec.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Alephant::LogSystem do
4
- before(:each) do
5
- sequencer = double()
6
- queue = double()
7
- cache = double()
8
- renderer = double()
9
-
10
- Alephant::Sequencer.stub(:create).and_return(sequencer)
11
- Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
12
- Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
13
- Alephant::Renderer.any_instance.stub(:initialize).and_return(renderer)
14
- end
15
-
16
- after(:each) do
17
- Alephant.logger = nil
18
- end
19
-
20
- let (:instance) { Alephant::Alephant }
21
- subject { Alephant::LogSystem }
22
-
23
- describe "::Alephant::LogSystem.logger" do
24
- context "Logger not provided" do
25
- it "return Ruby built-in Logger" do
26
- instance.new
27
- expect(Alephant.logger.class).to be(Logger)
28
- end
29
- end
30
-
31
- context "Logger provided" do
32
- it "return custom Logger" do
33
- class FakeLogger; end
34
- instance.new({}, FakeLogger.new)
35
- expect(Alephant.logger.class).to be(FakeLogger)
36
- end
37
- end
38
- end
39
- end
40
-
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Alephant::MultiRenderer do
4
- let(:component_id) { :foo }
5
- let(:data) {{ :foo => :bar }}
6
-
7
- subject { Alephant::MultiRenderer }
8
-
9
- before(:each) do
10
- File.stub(:directory?).and_return(true)
11
- end
12
-
13
- describe "initialize(view_base_path)" do
14
- context "view_base_path = invalid_path" do
15
- it "should raise InvalidViewPath" do
16
- File.stub(:directory?).and_return(false)
17
- expect {
18
- subject.new(component_id, './invalid_path')
19
- }.to raise_error(
20
- Alephant::Errors::InvalidViewPath
21
- )
22
- end
23
- end
24
-
25
- context "view_base_path = '.'" do
26
- it "sets base_path" do
27
- expect(subject.new(component_id, '.').base_path).to eq("./#{component_id}")
28
- end
29
- end
30
-
31
- context "view_base_path = nil" do
32
- it "sets base_path" do
33
- expect(subject.new(component_id).base_path).to eq(Alephant::MultiRenderer::DEFAULT_LOCATION)
34
- end
35
- end
36
- end
37
-
38
- describe "render_template(template_file, data, instance = nil)" do
39
- context "instance is not nil" do
40
- it "renders the specified template" do
41
- Alephant::MultiRenderer.any_instance.stub(:create_instance)
42
- Alephant::Renderer.any_instance.stub(:render).and_return('content')
43
-
44
- expect(
45
- subject.new(component_id, '.')
46
- .render_template('foo', data)
47
- ).to eq('content')
48
- end
49
- end
50
- end
51
-
52
- describe "render(data)" do
53
- it "calls render_template for each template found" do
54
- Alephant::MultiRenderer.any_instance.stub(:render_template)
55
- Alephant::MultiRenderer.any_instance.stub(
56
- :template_locations
57
- ).and_return(['foo', 'bar'])
58
-
59
- expect(
60
- subject.new(component_id, '.').render(data).size
61
- ).to eq(2)
62
- end
63
- end
64
-
65
- describe "create_instance(template_file, data)" do
66
- it "returns the model" do
67
- model = subject.new(
68
- component_id,
69
- 'fixtures/components'
70
- ).create_instance('foo', data)
71
-
72
- model.should be_an Alephant::Views::Base
73
- expect(model.data).to eq(data)
74
- end
75
-
76
- context "invalid model" do
77
- it 'should raise ViewModelNotFound' do
78
- expect {
79
- subject.new(
80
- component_id,
81
- @base_path
82
- ).create_instance(
83
- 'invalid_model',
84
- data
85
- )
86
- }.to raise_error(
87
- Alephant::Errors::ViewModelNotFound
88
- )
89
- end
90
- end
91
- end
92
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Alephant::Renderer do
4
- let(:template_file) { 'foo' }
5
- let(:base_path) { :base_path }
6
- let(:model) { :model }
7
- subject { Alephant::Renderer }
8
-
9
- before(:each) do
10
- @base_path = File.join(
11
- File.dirname(__FILE__),
12
- 'fixtures',
13
- 'components',
14
- 'foo'
15
- )
16
- end
17
-
18
- describe "initialize(template_file, base_path, model)" do
19
- context "template_file = :template_file" do
20
- it "sets the attribute template_file" do
21
- expect(subject.new(template_file, base_path, model).template_file).to eq(template_file)
22
- end
23
- end
24
- end
25
-
26
- describe "template()" do
27
- it "returns the template" do
28
- instance = subject.new(template_file, @base_path, model)
29
- template = instance.template
30
- expect(template).to eq("{{content}}\n")
31
- end
32
-
33
- context 'invalid template' do
34
- it 'should raise ViewTemplateNotFound' do
35
- instance = subject.new('invalid_example', @base_path, model)
36
-
37
- expect {
38
- instance.template
39
- }.to raise_error(
40
- Alephant::Errors::ViewTemplateNotFound
41
- )
42
- end
43
- end
44
- end
45
-
46
- describe "render()" do
47
- it 'renders a template returned from template(template_file)' do
48
- Mustache
49
- .any_instance
50
- .stub(:render)
51
- .with(:template, :model)
52
- .and_return(:content)
53
-
54
- Alephant::Renderer
55
- .any_instance
56
- .stub(:template)
57
- .and_return(:template)
58
-
59
- expect(subject.new(template_file, @base_path, model).render).to eq(:content)
60
- end
61
- end
62
- end
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- describe Alephant::Sequencer do
5
- let(:ident) { :ident }
6
- let(:jsonpath) { :jsonpath }
7
-
8
- describe ".create(table_name, ident, jsonpath)" do
9
- it "should return a Sequencer" do
10
- Alephant::Sequencer::SequenceTable.any_instance.stub(:create)
11
- expect(subject.create(:table_name, ident, jsonpath)).to be_a Alephant::Sequencer::Sequencer
12
- end
13
- end
14
-
15
- describe Alephant::Sequencer::Sequencer do
16
- let(:data) { double() }
17
- let(:last_seen) { 42 }
18
- let(:sequence_table) { double().tap { |o| o.stub(:create) } }
19
- subject { Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath) }
20
-
21
- describe "#initialize(opts, id)" do
22
- it "sets @jsonpath, @ident" do
23
- expect(subject.jsonpath).to eq(jsonpath)
24
- expect(subject.ident).to eq(ident)
25
- end
26
-
27
- it "calls create on sequence_table" do
28
- table = double()
29
- table.should_receive(:create)
30
-
31
- Alephant::Sequencer::Sequencer.new(table, ident, jsonpath)
32
- end
33
- end
34
-
35
- describe "#get_last_seen" do
36
- it "returns sequence_table.sequence_for(ident)" do
37
- table = double()
38
- table.stub(:create)
39
- table.should_receive(:sequence_for).with(ident).and_return(:expected_value)
40
-
41
- expect(
42
- Alephant::Sequencer::Sequencer.new(table, ident).get_last_seen
43
- ).to eq(:expected_value)
44
- end
45
- end
46
-
47
- describe "#set_last_seen(data)" do
48
- before(:each) do
49
- Alephant::Sequencer::Sequencer.any_instance.stub(:sequence_id_from).and_return(last_seen)
50
- end
51
-
52
- it "calls set_sequence_for(ident, last_seen)" do
53
- table = double()
54
- table.stub(:create)
55
- table.should_receive(:set_sequence_for).with(ident, last_seen)
56
-
57
- Alephant::Sequencer::Sequencer.new(table, ident).set_last_seen(data)
58
- end
59
- end
60
-
61
- describe "#sequential?(data, jsonpath)" do
62
-
63
- before(:each) do
64
- Alephant::Sequencer::Sequencer.any_instance.stub(:get_last_seen).and_return(1)
65
- data.stub(:body).and_return('sequence_id' => id_value)
66
- end
67
-
68
- context "jsonpath = '$.sequence_id'" do
69
- let(:jsonpath) { '$.sequence_id' }
70
- subject { Alephant::Sequencer::Sequencer.new(sequence_table, :ident, jsonpath) }
71
- context "sequential" do
72
- let(:id_value) { 2 }
73
- it "is true" do
74
- expect(subject.sequential?(data)).to be_true
75
- end
76
- end
77
-
78
- context "nonsequential" do
79
- let(:id_value) { 0 }
80
- it "is false" do
81
- expect(subject.sequential?(data)).to be_false
82
- end
83
- end
84
- end
85
-
86
- context "jsonpath = nil" do
87
- let(:jsonpath) { nil }
88
- subject { Alephant::Sequencer::Sequencer.new(sequence_table, :ident, jsonpath) }
89
-
90
- context "sequential" do
91
- let(:id_value) { 2 }
92
- it "is true" do
93
- expect(subject.sequential?(data)).to be_true
94
- end
95
- end
96
-
97
- context "nonsequential" do
98
- let(:id_value) { 0 }
99
- it "is false" do
100
- expect(subject.sequential?(data)).to be_false
101
- end
102
- end
103
- end
104
-
105
- end
106
- end
107
- end