binder_core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/.gitignore +13 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +19 -0
  5. data/README.markdown +86 -0
  6. data/Rakefile +1 -0
  7. data/binder_core.gemspec +24 -0
  8. data/lib/binder_core/asset.rb +45 -0
  9. data/lib/binder_core/binder.rb +26 -0
  10. data/lib/binder_core/compiler.rb +97 -0
  11. data/lib/binder_core/config.rb +98 -0
  12. data/lib/binder_core/console.rb +63 -0
  13. data/lib/binder_core/debug/stack.rb +86 -0
  14. data/lib/binder_core/defaults.rb +42 -0
  15. data/lib/binder_core/definition.rb +12 -0
  16. data/lib/binder_core/file_context.rb +46 -0
  17. data/lib/binder_core/file_ref.rb +38 -0
  18. data/lib/binder_core/folder_context.rb +55 -0
  19. data/lib/binder_core/parser.rb +82 -0
  20. data/lib/binder_core/parsers/asset_parser.rb +7 -0
  21. data/lib/binder_core/parsers/folder_parser.rb +7 -0
  22. data/lib/binder_core/parsers/null_parser.rb +6 -0
  23. data/lib/binder_core/parsers/text_parser.rb +11 -0
  24. data/lib/binder_core/registry.rb +45 -0
  25. data/lib/binder_core/scanner.rb +36 -0
  26. data/lib/binder_core/settings.rb +23 -0
  27. data/lib/binder_core/version.rb +3 -0
  28. data/lib/binder_core.rb +44 -0
  29. data/spec/binder_core/asset_spec.rb +64 -0
  30. data/spec/binder_core/binder_spec.rb +48 -0
  31. data/spec/binder_core/compiler_spec.rb +132 -0
  32. data/spec/binder_core/config_spec.rb +146 -0
  33. data/spec/binder_core/console_spec.rb +60 -0
  34. data/spec/binder_core/debug/stack_spec.rb +90 -0
  35. data/spec/binder_core/defaults_spec.rb +43 -0
  36. data/spec/binder_core/definition_spec.rb +20 -0
  37. data/spec/binder_core/file_context_spec.rb +79 -0
  38. data/spec/binder_core/file_ref_spec.rb +43 -0
  39. data/spec/binder_core/folder_context_spec.rb +104 -0
  40. data/spec/binder_core/parser_spec.rb +72 -0
  41. data/spec/binder_core/parsers/asset_parser_spec.rb +14 -0
  42. data/spec/binder_core/parsers/folder_parser_spec.rb +15 -0
  43. data/spec/binder_core/parsers/null_parser_spec.rb +9 -0
  44. data/spec/binder_core/parsers/text_parser_spec.rb +16 -0
  45. data/spec/binder_core/registry_spec.rb +61 -0
  46. data/spec/binder_core/scanner_spec.rb +79 -0
  47. data/spec/binder_core/settings_spec.rb +32 -0
  48. data/spec/binder_core_spec.rb +87 -0
  49. data/spec/spec_helper.rb +19 -0
  50. data/spec/support/content/test/_hidden_file.txt +1 -0
  51. data/spec/support/content/test/_hidden_folder/childofhiddenfolder.txt +1 -0
  52. data/spec/support/content/test/emptyfolder/_ignore.txt +1 -0
  53. data/spec/support/content/test/logo.png +0 -0
  54. data/spec/support/content/test/subfolder/subtext.txt +1 -0
  55. data/spec/support/content/test/testfile.txt +5 -0
  56. data/spec/support/content/test/unknown.tmp +1 -0
  57. data/spec/support/parsers/test_parsers.rb +20 -0
  58. metadata +147 -0
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe BinderCore::FolderParser do
4
+ let(:path) { File.join(BINDER_DEFAULT_DIR, "test") }
5
+ let(:file) { BinderCore::FileRef.new path }
6
+ let(:context) { double("FileContext", :file => file ) }
7
+ let(:content) { {:file => "value"} }
8
+
9
+ it "should call descend into a folder and add the response to to file context data" do
10
+ parser = BinderCore::FolderParser.new context
11
+ context.should_receive(:descend).and_return(:data => content)
12
+ context.should_receive(:data=).with(content)
13
+ parser.parse
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe BinderCore::NullParser do
4
+ it "should do nothing with the context when parse is callled" do
5
+ context = double("FileContext")
6
+ parser = BinderCore::NullParser.new context
7
+ parser.parse
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe BinderCore::TextParser do
6
+ let(:path) { File.join(BINDER_DEFAULT_DIR, "test", "testfile.txt") }
7
+ let(:file) { BinderCore::FileRef.new path }
8
+ let(:context) { double("FileContext", :file => file ) }
9
+ let(:content) { "This is a test file\n\nTwo lines down\n\nSymbols: \"\"'\\|[]{},.<>/?`~±§!@£$%^&*()_+-=" }
10
+
11
+ it "should read a UTF-8 text file" do
12
+ parser = BinderCore::TextParser.new context
13
+ context.should_receive(:data=).with(content)
14
+ parser.parse
15
+ end
16
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe BinderCore::Registry do
4
+ let(:path) { "/test/" }
5
+ let(:binder) { BinderCore::Binder.new(:object) }
6
+ let(:other_binder) { BinderCore::Binder.new(:string) }
7
+ let(:registry_name) { "Binder" }
8
+
9
+ subject { BinderCore::Registry.new(registry_name) }
10
+
11
+ it { should be_kind_of(Enumerable) }
12
+
13
+ it "finds a registered binder" do
14
+ subject.add(binder)
15
+ subject.find(binder.name).should == binder
16
+ end
17
+
18
+ it "raises when finding an unregistered binder" do
19
+ expect { subject.find(:bogus) }.to raise_error(ArgumentError, "Binder not registered: bogus")
20
+ end
21
+
22
+ it "adds and returns a binder" do
23
+ subject.add(binder).should == binder
24
+ end
25
+
26
+ it "knows that a binder is registered by symbol" do
27
+ subject.add(binder)
28
+ subject.should be_registered(binder.name.to_sym)
29
+ end
30
+
31
+ it "knows that a binder is registered by string" do
32
+ subject.add(binder)
33
+ subject.should be_registered(binder.name.to_s)
34
+ end
35
+
36
+ it "knows that a binder isn't registered" do
37
+ subject.should_not be_registered("bogus")
38
+ end
39
+
40
+ it "can be accessed like a hash" do
41
+ subject.add(binder)
42
+ subject[binder.name].should == binder
43
+ end
44
+
45
+ it "iterates registered binders" do
46
+ subject.add(binder)
47
+ subject.add(other_binder)
48
+ subject.to_a.should =~ [binder, other_binder]
49
+ end
50
+
51
+ it "doesn't allow a duplicate name" do
52
+ expect { 2.times { subject.add(binder) } }.
53
+ to raise_error(BinderCore::DuplicateDefinitionError, "Binder already registered: object")
54
+ end
55
+
56
+ it "clears registered binders" do
57
+ subject.add(binder)
58
+ subject.clear
59
+ subject.count.should be_zero
60
+ end
61
+ end
@@ -0,0 +1,79 @@
1
+ require "spec_helper"
2
+
3
+ describe BinderCore::Scanner do
4
+ describe "#scan" do
5
+ let(:stack) { double("stackMock").as_null_object }
6
+ let(:console) { double("ConsoleMock", :stack => stack) }
7
+ let(:context) { double("FileConextMock", :console => console, :route => [] ).as_null_object }
8
+ let(:config) { double("ConfigMock") }
9
+ let(:parser) { double("ParserMock" ).as_null_object }
10
+
11
+ before(:each) do
12
+ BinderCore::FileContext.should_receive(:new).and_return(context)
13
+ BinderCore::Config.should_receive(:new).with(context).and_return(config)
14
+ BinderCore::Scanner.should_receive(:get_parser_for).with(context).and_return(parser)
15
+ end
16
+ it "should create and configure a new file context" do
17
+ BinderCore::Scanner.scan lambda { |confg| }
18
+ end
19
+
20
+ it "should add the file context to the stack" do
21
+ stack.should_receive(:add_file).with( [], context)
22
+ BinderCore::Scanner.scan lambda { |confg| }
23
+ end
24
+
25
+ it "should parse the file context and return it" do
26
+ parser.should_receive(:parse)
27
+ BinderCore::Scanner.scan( lambda { |confg| }).should == context
28
+ end
29
+ end
30
+
31
+ describe "#get_parser_for" do
32
+ it "should return the first parser that matches file context" do
33
+ rules = [double("RuleMock1"), double("RuleMock2"),double("RuleMock3")]
34
+ parsers = [double("ParserMock1"), double("ParserMock2"),double("ParserMock3")]
35
+ context = double("ContextMock")
36
+ context.should_receive(:rules).and_return(rules)
37
+ context.should_receive(:parsers).and_return(parsers)
38
+ i = 0
39
+ [*rules,*parsers].each do |defn|
40
+ if i < 3
41
+ defn.should_receive(:test).and_return(nil)
42
+ elsif i==3
43
+ defn.should_receive(:test).and_return(BinderCore::Parser)
44
+ else
45
+ defn.should_not_receive(:test)
46
+ end
47
+ i+=1
48
+ end
49
+ BinderCore::Scanner.send(:get_parser_for,context)
50
+ end
51
+ end
52
+
53
+ describe "#descend" do
54
+ let(:raw) { {:data => "value", :assets => []} }
55
+ let(:context) { double("FileContextMock", :raw => raw).as_null_object }
56
+
57
+ before(:each) do
58
+ BinderCore::FolderContext.should_receive(:new).and_return(context)
59
+ end
60
+
61
+ it "should crate a new folder context" do
62
+ raw = BinderCore::Scanner.descend lambda{ |config| }
63
+ end
64
+
65
+ it "should call parse files on the folder context and return the result" do
66
+ context.should_receive(:parse_files).and_return raw
67
+ BinderCore::Scanner.descend(lambda{ |config| }).should == raw
68
+ end
69
+
70
+ it "should execute a passed in block on a config object" do
71
+ config = double("Config")
72
+ config.should_receive("test")
73
+ BinderCore::Scanner.descend lambda{ |c|
74
+ config.test
75
+ c.should be_kind_of(BinderCore::Config)
76
+ }
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe BinderCore::Settings do
4
+ before(:each) do
5
+ BinderCore::Settings.configure do
6
+ config.base_asset_url = "test"
7
+ config.content_folder = "test"
8
+ end
9
+ end
10
+
11
+ it "should allow configure call with a proc that has access to instance methods" do
12
+ BinderCore::Settings.config.base_asset_url.should == "test"
13
+ BinderCore::Settings.config.content_folder.should == "test"
14
+ end
15
+
16
+ it "should clone the comfig object when propegate is called" do
17
+ conf = BinderCore::Settings.config
18
+ conf2 = BinderCore::Settings.propegate
19
+ conf2.base_asset_url = "test2"
20
+ conf2.content_folder = "test2"
21
+
22
+ conf.base_asset_url.should_not == conf2.base_asset_url
23
+ conf.content_folder.should_not == conf2.content_folder
24
+ end
25
+ end
26
+
27
+ describe BinderCore::Settings::Config do
28
+ it "should provide a list of its public properties through prop_list" do
29
+ c = BinderCore::Settings::Config.new
30
+ c.prop_list.should == [:base_asset_folder, :base_asset_folder=, :base_asset_url, :base_asset_url=, :content_folder, :content_folder=, :folder_size_limit_mb, :folder_size_limit_mb=]
31
+ end
32
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe BinderCore do
6
+ describe "#define" do
7
+ after(:each) { BinderCore.binders.clear }
8
+
9
+ it "should return a Binder data object from binder_by_name method" do
10
+ test = BinderCore.define :test
11
+ test.should_not be_nil
12
+ test.name.should == :test
13
+ end
14
+
15
+ it "should register a second binder object with a different name" do
16
+ BinderCore.define :test
17
+ newname = :test2
18
+ test2 = BinderCore.define newname
19
+ test2.should_not be_nil
20
+ test2.name.should == newname
21
+ end
22
+
23
+ it "should add a config Proc to the Binder Object" do
24
+ test = BinderCore.define( :test ) {}
25
+ test.config.should be_a(Proc)
26
+ end
27
+ end
28
+
29
+ describe "#binder_by_name" do
30
+ before(:each) do
31
+ @test = BinderCore.define :test
32
+ end
33
+
34
+ it "should get the binder object by its name" do
35
+ binder = BinderCore.binder_by_name "test"
36
+ binder.should == @test
37
+ end
38
+ end
39
+
40
+ describe "#build" do
41
+ before(:all) do
42
+ BinderCore::Compiler.configure do
43
+ config.base_asset_url = ASSET_BASE_URL
44
+ config.content_folder = BINDER_DEFAULT_DIR
45
+ end
46
+ BinderCore.binders.clear
47
+ BinderCore.define :test
48
+ @binder = BinderCore.compile("test")
49
+ @data = @binder.raw[:data]
50
+ @assets = @binder.raw[:assets]
51
+ end
52
+ after(:all) { BinderCore.binders.clear }
53
+
54
+ it "should build the feed from the test content folder" do
55
+ @data.should_not be_nil
56
+ end
57
+
58
+ it "should should have a testfile property with the contents of testfile.txt" do
59
+ @data["testfile"].should == "This is a test file\n\nTwo lines down\n\nSymbols: \"\"'\\|[]{},.<>/?`~±§!@£$%^&*()_+-="
60
+ end
61
+
62
+ it "should have an asset for the logo png and the asset should be in the assets array" do
63
+ asset = @data["logo"]
64
+ asset.should be_kind_of(BinderCore::Asset)
65
+ asset.file.path.should == File.join(BINDER_DEFAULT_DIR, "test", "logo.png")
66
+ asset.asset_url.should == "http://www.BinderCore.com/assets/test/logo.png"
67
+ @assets.should include(asset)
68
+ end
69
+
70
+ it "should have set the base path property of each asset object" do
71
+ @assets.each { |asset| asset.base_url.should == ASSET_BASE_URL }
72
+ end
73
+
74
+ it "should ignore empty folders" do
75
+ @data.keys.should_not include("emptyfolder")
76
+ end
77
+
78
+ it "should ignore files/folders with names beginning with an underscore" do
79
+ @data.keys.should_not include("_hidden_file")
80
+ @data.keys.should_not include("_hidden_folder")
81
+ end
82
+
83
+ it "should ignore files types it doesnt recognise" do
84
+ @data.keys.should_not include("unknown")
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'rspec/autorun'
7
+ require 'rspec/mocks'
8
+
9
+ require "binder_core"
10
+
11
+ RSpec.configure do |config|
12
+
13
+ BINDER_DEFAULT_DIR = File.join(File.dirname(__FILE__),"support", "content")
14
+ ASSET_BASE_URL = "http://www.BinderCore.com/assets/"
15
+
16
+ config.after do
17
+
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ This should not be added to the feed because the file name starts with an underscore
@@ -0,0 +1 @@
1
+ this should not be in the feed because a parent folder should be hidden
@@ -0,0 +1 @@
1
+ this files is ignored so the containing folder is considered emtpy
Binary file
@@ -0,0 +1 @@
1
+ This is sub text
@@ -0,0 +1,5 @@
1
+ This is a test file
2
+
3
+ Two lines down
4
+
5
+ Symbols: ""'\|[]{},.<>/?`~±§!@£$%^&*()_+-=
@@ -0,0 +1 @@
1
+ this is an unknown file format and should be ignored
@@ -0,0 +1,20 @@
1
+ module TestParsers
2
+ class TestParser < BinderCore::Parser
3
+ def parse
4
+ add "test_parser"
5
+ end
6
+ end
7
+
8
+ class TestAssetParser < BinderCore::Parser
9
+ def parse
10
+ add new_asset( @context.file.path).with_name( @context.file.name )
11
+ end
12
+ end
13
+
14
+ class TestFolderParser < BinderCore::Parser
15
+ def parse
16
+ ret = {:file_key => "file_value"}
17
+ add ret
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binder_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ruaidhri Devery
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Ruby framework for compiling data from a file system
31
+ email:
32
+ - info@fluid.ie
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.markdown
42
+ - Rakefile
43
+ - binder_core.gemspec
44
+ - lib/binder_core.rb
45
+ - lib/binder_core/asset.rb
46
+ - lib/binder_core/binder.rb
47
+ - lib/binder_core/compiler.rb
48
+ - lib/binder_core/config.rb
49
+ - lib/binder_core/console.rb
50
+ - lib/binder_core/debug/stack.rb
51
+ - lib/binder_core/defaults.rb
52
+ - lib/binder_core/definition.rb
53
+ - lib/binder_core/file_context.rb
54
+ - lib/binder_core/file_ref.rb
55
+ - lib/binder_core/folder_context.rb
56
+ - lib/binder_core/parser.rb
57
+ - lib/binder_core/parsers/asset_parser.rb
58
+ - lib/binder_core/parsers/folder_parser.rb
59
+ - lib/binder_core/parsers/null_parser.rb
60
+ - lib/binder_core/parsers/text_parser.rb
61
+ - lib/binder_core/registry.rb
62
+ - lib/binder_core/scanner.rb
63
+ - lib/binder_core/settings.rb
64
+ - lib/binder_core/version.rb
65
+ - spec/binder_core/asset_spec.rb
66
+ - spec/binder_core/binder_spec.rb
67
+ - spec/binder_core/compiler_spec.rb
68
+ - spec/binder_core/config_spec.rb
69
+ - spec/binder_core/console_spec.rb
70
+ - spec/binder_core/debug/stack_spec.rb
71
+ - spec/binder_core/defaults_spec.rb
72
+ - spec/binder_core/definition_spec.rb
73
+ - spec/binder_core/file_context_spec.rb
74
+ - spec/binder_core/file_ref_spec.rb
75
+ - spec/binder_core/folder_context_spec.rb
76
+ - spec/binder_core/parser_spec.rb
77
+ - spec/binder_core/parsers/asset_parser_spec.rb
78
+ - spec/binder_core/parsers/folder_parser_spec.rb
79
+ - spec/binder_core/parsers/null_parser_spec.rb
80
+ - spec/binder_core/parsers/text_parser_spec.rb
81
+ - spec/binder_core/registry_spec.rb
82
+ - spec/binder_core/scanner_spec.rb
83
+ - spec/binder_core/settings_spec.rb
84
+ - spec/binder_core_spec.rb
85
+ - spec/spec_helper.rb
86
+ - spec/support/content/test/_hidden_file.txt
87
+ - spec/support/content/test/_hidden_folder/childofhiddenfolder.txt
88
+ - spec/support/content/test/emptyfolder/_ignore.txt
89
+ - spec/support/content/test/logo.png
90
+ - spec/support/content/test/subfolder/subtext.txt
91
+ - spec/support/content/test/testfile.txt
92
+ - spec/support/content/test/unknown.tmp
93
+ - spec/support/parsers/test_parsers.rb
94
+ homepage: https://github.com/rur/Binder-Core
95
+ licenses: []
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project: binder_core
114
+ rubygems_version: 1.8.24
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Folder content compiler
118
+ test_files:
119
+ - spec/binder_core/asset_spec.rb
120
+ - spec/binder_core/binder_spec.rb
121
+ - spec/binder_core/compiler_spec.rb
122
+ - spec/binder_core/config_spec.rb
123
+ - spec/binder_core/console_spec.rb
124
+ - spec/binder_core/debug/stack_spec.rb
125
+ - spec/binder_core/defaults_spec.rb
126
+ - spec/binder_core/definition_spec.rb
127
+ - spec/binder_core/file_context_spec.rb
128
+ - spec/binder_core/file_ref_spec.rb
129
+ - spec/binder_core/folder_context_spec.rb
130
+ - spec/binder_core/parser_spec.rb
131
+ - spec/binder_core/parsers/asset_parser_spec.rb
132
+ - spec/binder_core/parsers/folder_parser_spec.rb
133
+ - spec/binder_core/parsers/null_parser_spec.rb
134
+ - spec/binder_core/parsers/text_parser_spec.rb
135
+ - spec/binder_core/registry_spec.rb
136
+ - spec/binder_core/scanner_spec.rb
137
+ - spec/binder_core/settings_spec.rb
138
+ - spec/binder_core_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/support/content/test/_hidden_file.txt
141
+ - spec/support/content/test/_hidden_folder/childofhiddenfolder.txt
142
+ - spec/support/content/test/emptyfolder/_ignore.txt
143
+ - spec/support/content/test/logo.png
144
+ - spec/support/content/test/subfolder/subtext.txt
145
+ - spec/support/content/test/testfile.txt
146
+ - spec/support/content/test/unknown.tmp
147
+ - spec/support/parsers/test_parsers.rb