mbj-assets 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 34583cf1a54e359e7db67d15f1191d2d3d00881d
4
+ data.tar.gz: 46485a80f1b0c267ba683d08735c02ffd574ad96
5
+ SHA512:
6
+ metadata.gz: c73494fa9667dbe84ea1fd36363ad5bcd3ef7ec83cd702ab72066d43e47323942afab24ee6cb11921a22b2b9f1e54a307ea89f601ee6879ad3eefe2d1bded22a
7
+ data.tar.gz: c6f44c87c74d794d4115e2096b2246c84fb34fdaca653a9f118e98563015b8fd3cc1cb8b2126116e194d6df3af68198c04abcc5d817fb24d8f11ee6a501bdb31
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /Gemfile.lock
2
+ /.sass-cache
3
+ /tmp
4
+ /.bundle
5
+ /vendor
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ script: 'bundle exec rake ci'
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - ruby-head
8
+ - jruby-19mode
9
+ - jruby-head
10
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'devtools', :git => 'https://github.com/rom-rb/devtools.git'
6
+ eval File.read('Gemfile.devtools')
data/Gemfile.devtools ADDED
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ group :development do
4
+ gem 'rake', '~> 10.1.0'
5
+ gem 'rspec', '~> 2.13.0'
6
+ gem 'yard', '~> 0.8.6.1'
7
+ end
8
+
9
+ group :yard do
10
+ gem 'kramdown', '~> 1.0.1'
11
+ end
12
+
13
+ group :guard do
14
+ gem 'guard', '~> 1.8.1'
15
+ gem 'guard-bundler', '~> 1.0.0'
16
+ gem 'guard-rspec', '~> 3.0.2'
17
+
18
+ # file system change event handling
19
+ gem 'listen', '~> 1.2.2'
20
+ gem 'rb-fchange', '~> 0.0.6', :require => false
21
+ gem 'rb-fsevent', '~> 0.9.3', :require => false
22
+ gem 'rb-inotify', '~> 0.9.0', :require => false
23
+
24
+ # notification handling
25
+ gem 'libnotify', '~> 0.8.0', :require => false
26
+ gem 'rb-notifu', '~> 0.0.4', :require => false
27
+ gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
28
+ end
29
+
30
+ group :metrics do
31
+ gem 'backports', '~> 3.3', '>= 3.3.2'
32
+ gem 'coveralls', '~> 0.6.7'
33
+ gem 'flay', '~> 2.3.0'
34
+ gem 'flog', '~> 4.1.0'
35
+ gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
36
+ gem 'simplecov', '~> 0.7.1'
37
+ gem 'yardstick', '~> 0.9.6'
38
+
39
+ platforms :ruby_19 do
40
+ gem 'yard-spellcheck', '~> 0.1.5'
41
+ end
42
+
43
+ platforms :ruby_19, :ruby_20 do
44
+ gem 'mutant', '~> 0.3.0.beta4'
45
+ end
46
+
47
+ platforms :rbx do
48
+ gem 'pelusa', '~> 0.2.2'
49
+ end
50
+ end
51
+
52
+ group :benchmarks do
53
+ gem 'rbench', '~> 0.2.3'
54
+ end
55
+
56
+ platform :jruby do
57
+ group :jruby do
58
+ gem 'jruby-openssl', '~> 0.8.5'
59
+ end
60
+ end
data/Guardfile ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ guard :bundler do
4
+ watch('Gemfile')
5
+ end
6
+
7
+ guard :rspec, :version => 2 do
8
+ # run all specs if the spec_helper or supporting files files are modified
9
+ watch('spec/spec_helper.rb') { 'spec/unit' }
10
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec/unit' }
11
+
12
+ # run unit specs if associated lib code is modified
13
+ watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
14
+ watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec/unit' }
15
+
16
+ # run a spec if it is modified
17
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
18
+ end
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'devtools'
2
+ Devtools.init_rake_tasks
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ * Mutation coverage
2
+ * Make compilers work from strings!
data/assets.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'mbj-assets'
5
+ gem.version = '0.0.3'
6
+ gem.authors = [ 'Markus Schirp' ]
7
+ gem.email = [ 'mbj@schirp-dso.com' ]
8
+ gem.description = 'Playground for a small assets system'
9
+ gem.summary = gem.description
10
+ gem.homepage = 'https://github.com/mbj/assets'
11
+
12
+ gem.require_paths = [ 'lib' ]
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- spec`.split("\n")
15
+ gem.extra_rdoc_files = %w[TODO]
16
+
17
+ gem.add_runtime_dependency('adamantium', '~> 0.0.8')
18
+ gem.add_runtime_dependency('ice_nine', '~> 0.8.0')
19
+ gem.add_runtime_dependency('descendants_tracker', '~> 0.0.1')
20
+ gem.add_runtime_dependency('concord', '~> 0.1.1')
21
+ gem.add_runtime_dependency('equalizer', '~> 0.0.5')
22
+ gem.add_runtime_dependency('response', '~> 0.0.2')
23
+ gem.add_runtime_dependency('request', '~> 0.0.2')
24
+ gem.add_runtime_dependency('abstract_type', '~> 0.0.5')
25
+ gem.add_runtime_dependency('anima', '~> 0.0.5')
26
+ gem.add_runtime_dependency('sass', '~> 3.2.4')
27
+ gem.add_runtime_dependency('coffee-script', '~> 2.2.0')
28
+ end
data/config/flay.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 12
3
+ total_score: 107
data/config/flog.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 9.4
data/config/mutant.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ name: assets
3
+ namespace: Assets
data/config/reek.yml ADDED
@@ -0,0 +1,93 @@
1
+ ---
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+ exclude: []
5
+ enabled: false # Todo enable
6
+ reject:
7
+ - !ruby/regexp /^.$/
8
+ - !ruby/regexp /[0-9]$/
9
+ - !ruby/regexp /[A-Z]/
10
+ TooManyMethods:
11
+ max_methods: 10
12
+ exclude: []
13
+ enabled: true
14
+ max_instance_variables: 3
15
+ UncommunicativeMethodName:
16
+ accept:
17
+ - sha1
18
+ exclude: []
19
+ enabled: true
20
+ reject:
21
+ - !ruby/regexp /^[a-z]$/
22
+ - !ruby/regexp /[0-9]$/
23
+ - !ruby/regexp /[A-Z]/
24
+ LongParameterList:
25
+ max_params: 2
26
+ exclude: []
27
+ enabled: true
28
+ overrides: {}
29
+ FeatureEnvy:
30
+ exclude:
31
+ - Assets::Environment::Cache#miss # False positive
32
+ enabled: true
33
+ ClassVariable:
34
+ exclude: []
35
+ enabled: true
36
+ BooleanParameter:
37
+ exclude: []
38
+ enabled: true
39
+ IrresponsibleModule:
40
+ exclude: []
41
+ enabled: false # Fix false positives and reenable
42
+ UncommunicativeModuleName:
43
+ accept: []
44
+ exclude: []
45
+ enabled: true
46
+ reject:
47
+ - !ruby/regexp /^.$/
48
+ - !ruby/regexp /[0-9]$/
49
+ NestedIterators:
50
+ ignore_iterators: []
51
+ exclude: []
52
+ enabled: true
53
+ max_allowed_nesting: 1
54
+ TooManyStatements:
55
+ max_statements: 8
56
+ exclude: []
57
+ enabled: true
58
+ DuplicateMethodCall:
59
+ allow_calls: []
60
+ exclude: []
61
+ enabled: true
62
+ max_calls: 1
63
+ UtilityFunction:
64
+ max_helper_calls: 0
65
+ exclude: []
66
+ enabled: true
67
+ Attribute:
68
+ exclude: []
69
+ enabled: false
70
+ UncommunicativeVariableName:
71
+ accept: []
72
+ exclude: []
73
+ enabled: false
74
+ reject:
75
+ - !ruby/regexp /^.$/
76
+ - !ruby/regexp /[0-9]$/
77
+ - !ruby/regexp /[A-Z]/
78
+ RepeatedConditional:
79
+ exclude: []
80
+ enabled: true
81
+ max_ifs: 1
82
+ DataClump:
83
+ exclude: []
84
+ enabled: true
85
+ max_copies: 2
86
+ min_clump_size: 2
87
+ ControlParameter:
88
+ exclude: []
89
+ enabled: true
90
+ LongYieldList:
91
+ max_params: 1
92
+ exclude: []
93
+ enabled: true
data/config/roodi.yml ADDED
@@ -0,0 +1,26 @@
1
+ ---
2
+ AbcMetricMethodCheck:
3
+ score: 12.2
4
+ AssignmentInConditionalCheck: {}
5
+ CaseMissingElseCheck: {}
6
+ ClassLineCountCheck:
7
+ line_count: 324
8
+ ClassNameCheck:
9
+ pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
10
+ ClassVariableCheck: {}
11
+ CyclomaticComplexityBlockCheck:
12
+ complexity: 2
13
+ CyclomaticComplexityMethodCheck:
14
+ complexity: 4
15
+ EmptyRescueBodyCheck: {}
16
+ ForLoopCheck: {}
17
+ MethodLineCountCheck:
18
+ line_count: 8 # TODO decrease to 9
19
+ MethodNameCheck:
20
+ pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|<<|[+*&|-])\z/
21
+ ModuleLineCountCheck:
22
+ line_count: 376
23
+ ModuleNameCheck:
24
+ pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
25
+ ParameterNumberCheck:
26
+ parameter_count: 4 # TODO decrease to 2
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100.0
@@ -0,0 +1,24 @@
1
+ module Assets
2
+
3
+ # Abstract base class for asset
4
+ class Asset
5
+ include Adamantium, Anima.new(:name, :mime, :created_at, :size, :sha1, :body)
6
+
7
+ # Test if asset was fresh at specific point of time
8
+ #
9
+ # @param [Time] time
10
+ #
11
+ # @return [true]
12
+ # if asset is fresh at time
13
+ #
14
+ # @return [false]
15
+ # otherwise
16
+ #
17
+ # @api private
18
+ #
19
+ def fresh_at?(time)
20
+ time >= created_at
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,88 @@
1
+ module Assets
2
+ # Asset builder
3
+ class Builder
4
+
5
+ # Run builder
6
+ #
7
+ # @param [String] name
8
+ #
9
+ # @return [Rule]
10
+ #
11
+ # @api private
12
+ #
13
+ def self.run(name)
14
+ builder = new(name, Mime.from_name(name))
15
+ yield builder
16
+ Assets::Rule::Concat.new(name, builder.rules)
17
+ end
18
+
19
+ # Return rules
20
+ #
21
+ # @return [Enumerable<Rule>]
22
+ #
23
+ # @api private
24
+ #
25
+ attr_reader :rules
26
+
27
+ # Initialize object
28
+ #
29
+ # @param [String] name
30
+ # @param [Mime] mime
31
+ #
32
+ # @api private
33
+ #
34
+ # @return [undefined]
35
+ #
36
+ def initialize(name, mime)
37
+ @name, @mime, @rules = name, mime, []
38
+ end
39
+
40
+ # Use pacakges
41
+ #
42
+ # @param [Enumerable<Package>] packages
43
+ #
44
+ # @return [self]
45
+ #
46
+ # @api private
47
+ #
48
+ def packages(packages)
49
+ packages.each do |package|
50
+ package(package)
51
+ end
52
+ self
53
+ end
54
+
55
+ # Use package
56
+ #
57
+ # @param [Assets::Package]
58
+ #
59
+ # @return [self]
60
+ #
61
+ # @api private
62
+ #
63
+ def package(package)
64
+ package.mime(@mime).each do |rule|
65
+ append(rule)
66
+ end
67
+ self
68
+ end
69
+
70
+ # Add rule
71
+ #
72
+ # @param [Rule]
73
+ #
74
+ # @return [self]
75
+ #
76
+ # @api private
77
+ #
78
+ def append(rule)
79
+ unless rule.mime == @mime
80
+ raise
81
+ end
82
+
83
+ @rules << rule
84
+
85
+ self
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,113 @@
1
+ module Assets
2
+ class Environment
3
+ # Environment that caches assets
4
+ class Cache < self
5
+ include Adamantium::Flat, Equalizer.new(:environment)
6
+
7
+ # Return inner environment
8
+ #
9
+ # @return [Environment]
10
+ #
11
+ # @api private
12
+ #
13
+ attr_reader :environment
14
+
15
+ # Build cache environemnt
16
+ #
17
+ # @param [Enumerable<Rules>] rules
18
+ #
19
+ # @return [Cache]
20
+ #
21
+ # @api private
22
+ #
23
+ def self.build(rules)
24
+ new(Dynamic.new(rules))
25
+ end
26
+
27
+ # Initialize object
28
+ #
29
+ # @param [Environment] environment
30
+ #
31
+ # @return [undefined]
32
+ #
33
+ # @api private
34
+ #
35
+ def initialize(environment)
36
+ @environment, @cache = environment, {}
37
+ end
38
+
39
+ # Return rule
40
+ #
41
+ # @param [String] name
42
+ #
43
+ # @return [Rule]
44
+ # if found
45
+ #
46
+ # @return [nil]
47
+ # otherwise
48
+ #
49
+ # @api private
50
+ #
51
+ def rule(name)
52
+ environment.rule(name)
53
+ end
54
+
55
+ # Return asset
56
+ #
57
+ # @param [String] name
58
+ #
59
+ # @return [Asset]
60
+ # if found
61
+ #
62
+ # @return [nil]
63
+ # otherwise
64
+ #
65
+ def get(name)
66
+ rule = rule(name)
67
+ return unless rule
68
+
69
+ asset = @cache.fetch(name) do
70
+ return miss(rule)
71
+ end
72
+
73
+ hit(rule, asset)
74
+ end
75
+
76
+ private
77
+
78
+ # Process cache hit
79
+ #
80
+ # @param [Rule] rule
81
+ # @param [Asset] asset
82
+ #
83
+ # @return [Asset]
84
+ #
85
+ # @api private
86
+ #
87
+ def hit(rule, asset)
88
+ if rule.fresh_at?(asset.created_at)
89
+ return asset
90
+ end
91
+
92
+ miss(rule)
93
+ end
94
+
95
+ # Process cache miss
96
+ #
97
+ # @param [Rule] rule
98
+ #
99
+ # @return [Asset]
100
+ # if found
101
+ #
102
+ # @return [nil]
103
+ # otherwise
104
+ #
105
+ # @api private
106
+ #
107
+ def miss(rule)
108
+ @cache[rule.name] = rule.asset
109
+ end
110
+
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,56 @@
1
+ module Assets
2
+ class Environment
3
+
4
+ # Environment with dynamic asset compilation
5
+ class Dynamic < self
6
+ include Adamantium, Concord.new(:rules)
7
+
8
+ # Return index
9
+ #
10
+ # @return [Hash]
11
+ #
12
+ # @api private
13
+ #
14
+ def index
15
+ rules.each_with_object({}) do |rule, index|
16
+ index[rule.name] = rule
17
+ end
18
+ end
19
+ memoize :index
20
+
21
+ # Return rule for name
22
+ #
23
+ # @param [String] name
24
+ #
25
+ # @return [Rule]
26
+ # if found
27
+ #
28
+ # @return [nil]
29
+ # otherwise
30
+ #
31
+ # @api private
32
+ #
33
+ def rule(name)
34
+ index[name]
35
+ end
36
+
37
+ # Return asset for name
38
+ #
39
+ # @param [String] name
40
+ #
41
+ # @return [Asset]
42
+ # if found
43
+ #
44
+ # @return [nil]
45
+ # otherwise
46
+ #
47
+ # @api private
48
+ #
49
+ def get(name)
50
+ rule = rule(name)
51
+ rule && rule.asset
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,37 @@
1
+ module Assets
2
+ class Environment
3
+ # Static enviornment with precompiled assets
4
+ class Static < self
5
+ include Concord.new(:assets)
6
+
7
+ # Return index
8
+ #
9
+ # @return [Hash]
10
+ #
11
+ # @api private
12
+ #
13
+ def index
14
+ assets.each_with_object({}) do |asset, index|
15
+ index[asset.name]=asset
16
+ end
17
+ end
18
+
19
+ # Return asset
20
+ #
21
+ # @param [String] name
22
+ # name of asset
23
+ #
24
+ # @return [Asset]
25
+ # if found
26
+ #
27
+ # @return [nil]
28
+ # otherwise
29
+ #
30
+ # @api private
31
+ #
32
+ def get(name)
33
+ index[name]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ module Assets
2
+
3
+ # Abstract base class for asset environments
4
+ class Environment
5
+ include AbstractType
6
+
7
+ # Return rule
8
+ #
9
+ # @param [String] name
10
+ #
11
+ # @return [Rule]
12
+ # if found
13
+ #
14
+ # @return [nil]
15
+ # otherwise
16
+ #
17
+ # @api private
18
+ #
19
+ abstract_method :rule
20
+
21
+ # Return asset
22
+ #
23
+ # @return [Asset]
24
+ # if found
25
+ #
26
+ # @return [nil]
27
+ # otherwise
28
+ #
29
+ # @api private
30
+ #
31
+ abstract_method :get
32
+
33
+ end
34
+ end