fedux_org-stdlib 0.7.20 → 0.7.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/roles/typable.rb +166 -0
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/roles/typable_spec.rb +83 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f4527fb22b611d0a2eafdeeacda0ddbb8bbeabc
|
4
|
+
data.tar.gz: a6d760bbd9ecc7902e6d3bfe440b2be42ca56908
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3a96b663ce768db511aba23fc39c3eb213e9f9990683cca6e78b9b64a7033f89024efe5cf896c6e97b10251d9342e0f7909065b5135e48d2e16f5cf53cfe63d
|
7
|
+
data.tar.gz: cb67a095ea80acd945da543c6b289389a416ca0f2e556f6a9d89f68c9660b7a825ea960ca743e06bf56f4de492009344affd7ac4c87e77a3ef39f3422c6456f8
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,166 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module FeduxOrgStdlib
|
3
|
+
module Roles
|
4
|
+
# Typable
|
5
|
+
#
|
6
|
+
# If need to determine the file type of a object, you can include
|
7
|
+
# `FeduxOrgStdlib::Roles::Typeable`. You only need to define a method
|
8
|
+
# `source_path`, which is used by the included methods. It needs to return
|
9
|
+
# a `Pathname`.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# class MyClass
|
14
|
+
# include FeduxOrgStdlib::Roles::Typeable
|
15
|
+
#
|
16
|
+
# private
|
17
|
+
#
|
18
|
+
# attr_reader :source_path
|
19
|
+
#
|
20
|
+
# public
|
21
|
+
#
|
22
|
+
# def initialize(source_path:)
|
23
|
+
# @source_path = Pathname.new(source_path)
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# object = MyClass.new('images/image.png')
|
28
|
+
# object.type # => :image
|
29
|
+
#
|
30
|
+
# object = MyClass.new('images/image.css')
|
31
|
+
# object.type # => :stylesheet
|
32
|
+
# object.image? # => false
|
33
|
+
# object.stylesheet? # => true
|
34
|
+
module Typable
|
35
|
+
|
36
|
+
def source_path
|
37
|
+
fail NoMethodError, :source_path
|
38
|
+
end
|
39
|
+
|
40
|
+
# Check on file type
|
41
|
+
#
|
42
|
+
# @return [true, false]
|
43
|
+
# Is true if has type
|
44
|
+
def type?(t)
|
45
|
+
type == t
|
46
|
+
end
|
47
|
+
|
48
|
+
# Determine type of object
|
49
|
+
def type
|
50
|
+
@type ||= if image?
|
51
|
+
:image
|
52
|
+
elsif script?
|
53
|
+
:script
|
54
|
+
elsif stylesheet?
|
55
|
+
:stylesheet
|
56
|
+
elsif font?
|
57
|
+
:font
|
58
|
+
else
|
59
|
+
:unknown
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Is file?
|
64
|
+
def file?
|
65
|
+
source_path.file?
|
66
|
+
end
|
67
|
+
|
68
|
+
# Is it a valid
|
69
|
+
# @return [true, false]
|
70
|
+
# If it is valid return true
|
71
|
+
def valid?
|
72
|
+
file?
|
73
|
+
end
|
74
|
+
|
75
|
+
# Has file extensions
|
76
|
+
#
|
77
|
+
# @param [Array] exts
|
78
|
+
# The extensions to check
|
79
|
+
def extnames?(*exts)
|
80
|
+
!(extnames & exts.flatten).empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return extensions
|
84
|
+
def extnames
|
85
|
+
source_path.basename.to_s.scan(/(\.[^.]+)/).flatten
|
86
|
+
end
|
87
|
+
|
88
|
+
# Is image?
|
89
|
+
def image?
|
90
|
+
image_by_path? || (image_by_extension? && !font_by_path?)
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
# Is image by path?
|
96
|
+
def image_by_path?
|
97
|
+
source_path.dirname.basename.to_s == 'images' ||
|
98
|
+
source_path.dirname.basename.to_s == 'img'
|
99
|
+
end
|
100
|
+
|
101
|
+
# Is image by extension?
|
102
|
+
def image_by_extension?
|
103
|
+
extnames?(*%w(.gif .png .jpg .jpeg .webp .svg .svgz))
|
104
|
+
end
|
105
|
+
|
106
|
+
public
|
107
|
+
|
108
|
+
# Is stylesheet?
|
109
|
+
def stylesheet?
|
110
|
+
stylesheet_by_path? || stylesheet_by_extension?
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
# Is stylesheet by extension?
|
116
|
+
def stylesheet_by_extension?
|
117
|
+
extnames?(*%w(.css .sass .scss .styl .less))
|
118
|
+
end
|
119
|
+
|
120
|
+
# Is stylesheet by path?
|
121
|
+
def stylesheet_by_path?
|
122
|
+
source_path.dirname.basename.to_s == 'stylesheets' ||
|
123
|
+
source_path.dirname.basename.to_s == 'css'
|
124
|
+
end
|
125
|
+
|
126
|
+
public
|
127
|
+
|
128
|
+
# Is font?
|
129
|
+
def font?
|
130
|
+
font_by_path? || font_by_extension?
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
# Is font by path?
|
136
|
+
def font_by_path?
|
137
|
+
source_path.dirname.basename.to_s == 'fonts'
|
138
|
+
end
|
139
|
+
|
140
|
+
# Is font by extension?
|
141
|
+
def font_by_extension?
|
142
|
+
extnames?(*%w(.ttf .woff .eot .otf .svg .svgz))
|
143
|
+
end
|
144
|
+
|
145
|
+
public
|
146
|
+
|
147
|
+
# Is script?
|
148
|
+
def script?
|
149
|
+
script_by_path? || script_by_extension?
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
# Is script by path?
|
155
|
+
def script_by_path?
|
156
|
+
source_path.dirname.basename.to_s == 'javascripts' ||
|
157
|
+
source_path.dirname.basename.to_s == 'js'
|
158
|
+
end
|
159
|
+
|
160
|
+
# Is script by extension?
|
161
|
+
def script_by_extension?
|
162
|
+
extnames?(*%w(.js .coffee))
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'fedux_org_stdlib/roles/typable'
|
4
|
+
|
5
|
+
RSpec.describe FeduxOrgStdlib::Roles::Typable do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include FeduxOrgStdlib::Roles::Typable
|
9
|
+
|
10
|
+
attr_reader :source_path
|
11
|
+
|
12
|
+
def initialize(source_path:)
|
13
|
+
@source_path = Pathname.new(source_path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'use' do
|
19
|
+
let(:klass) do
|
20
|
+
Class.new do
|
21
|
+
include FeduxOrgStdlib::Roles::Typable
|
22
|
+
|
23
|
+
def initialize(source_path:)
|
24
|
+
@source_path = Pathname.new(source_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'fails if source_path-method is missing' do
|
30
|
+
object = klass.new(source_path: 'blub/image.png')
|
31
|
+
expect do
|
32
|
+
object.type
|
33
|
+
end.to raise_error NoMethodError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context '#type' do
|
38
|
+
it 'returns type' do
|
39
|
+
object = klass.new(source_path: 'blub/image.png')
|
40
|
+
expect(object.type).to eq :image
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context '#type?' do
|
45
|
+
it 'checks type' do
|
46
|
+
object = klass.new(source_path: 'blub/image.png')
|
47
|
+
expect(object).not_to be_type :script
|
48
|
+
expect(object).to be_type :image
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'extname' do
|
53
|
+
it 'returns file extension' do
|
54
|
+
object = klass.new(source_path: 'blub/image.png')
|
55
|
+
expect(object.extnames).to eq %w(.png)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns all file extensions' do
|
59
|
+
object = klass.new(source_path: 'blub/image.png.gz')
|
60
|
+
expect(object.extnames).to eq %w(.png .gz)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context '#extnames?' do
|
65
|
+
it 'checks if object has extnames' do
|
66
|
+
object = klass.new(source_path: 'blub/image.png.gz')
|
67
|
+
expect(object).to be_extnames %w(.png .gz)
|
68
|
+
expect(object).to be_extnames %w(.png )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context '#valid?' do
|
73
|
+
it 'succeeds if file exist' do
|
74
|
+
touch_file 'blub/image.png'
|
75
|
+
|
76
|
+
object = klass.new(source_path: 'blub/image.png')
|
77
|
+
|
78
|
+
in_current_dir do
|
79
|
+
expect(object).to be_valid
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/fedux_org_stdlib/rake_tasks/tests/travis.rb
|
142
142
|
- lib/fedux_org_stdlib/require_files.rb
|
143
143
|
- lib/fedux_org_stdlib/roles/comparable_by_name.rb
|
144
|
+
- lib/fedux_org_stdlib/roles/typable.rb
|
144
145
|
- lib/fedux_org_stdlib/roles/versionable.rb
|
145
146
|
- lib/fedux_org_stdlib/shell_language_detector.rb
|
146
147
|
- lib/fedux_org_stdlib/shell_language_detector/language.rb
|
@@ -196,6 +197,7 @@ files:
|
|
196
197
|
- spec/project/plan_spec.rb
|
197
198
|
- spec/project/report_spec.rb
|
198
199
|
- spec/project/taskjuggler_spec.rb
|
200
|
+
- spec/roles/typable_spec.rb
|
199
201
|
- spec/shell_language_detector_spec.rb
|
200
202
|
- spec/spec_helper.rb
|
201
203
|
- spec/support/aruba.rb
|
@@ -274,6 +276,7 @@ test_files:
|
|
274
276
|
- spec/project/plan_spec.rb
|
275
277
|
- spec/project/report_spec.rb
|
276
278
|
- spec/project/taskjuggler_spec.rb
|
279
|
+
- spec/roles/typable_spec.rb
|
277
280
|
- spec/shell_language_detector_spec.rb
|
278
281
|
- spec/spec_helper.rb
|
279
282
|
- spec/support/aruba.rb
|