Class: Scaffoldhub::Specification
- Inherits:
-
Object
- Object
- Scaffoldhub::Specification
- Defined in:
- lib/scaffoldhub/specification.rb
Constant Summary collapse
- @@files =
[]
- @@errors =
[]
[]
- @@gems =
[]
Class Method Summary collapse
- .add_file(src, dest, rename, type) ⇒ Object
- .add_tag(keyword) ⇒ Object
- .adjusted_base_url ⇒ Object
- .all_template_files_exist? ⇒ Boolean
- .has_base_url? ⇒ Boolean
- .has_description? ⇒ Boolean
- .has_name? ⇒ Boolean
- .has_screenshot? ⇒ Boolean
- .has_string_value?(value) ⇒ Boolean
- .remote_file_exists?(url) ⇒ Boolean
- .to_yaml ⇒ Object
- .valid? ⇒ Boolean
Instance Method Summary collapse
- #file(src, options = {}, type = :file) ⇒ Object
- #gem(*args) ⇒ Object
-
#initialize(&block) ⇒ Specification
constructor
A new instance of Specification.
- #metadata ⇒ Object
- #tag(keyword) ⇒ Object
- #template(src, options = {}) ⇒ Object
- #with_options(options, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Specification
Returns a new instance of Specification.
126 127 128 129 130 |
# File 'lib/scaffoldhub/specification.rb', line 126 def initialize(&block) @context_stack = [] @context_options = {} instance_eval(&block) if block_given? end |
Class Method Details
.add_file(src, dest, rename, type) ⇒ Object
55 56 57 |
# File 'lib/scaffoldhub/specification.rb', line 55 def add_file(src, dest, rename, type) @@files << { :type => type, :src => src, :rename => rename, :dest => dest } end |
.add_tag(keyword) ⇒ Object
59 60 61 |
# File 'lib/scaffoldhub/specification.rb', line 59 def add_tag(keyword) @@tags << keyword end |
.adjusted_base_url ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/scaffoldhub/specification.rb', line 78 def adjusted_base_url if base_url =~ /github.com\/([^\s]+\/[^\s]+)\/(tree|blob)\/(.*)$/ "https://github.com/#{$1}/raw/#{$3}" elsif base_url =~ /github.com\/([^\s^\/]+\/[^\s^\/]+)\/?$/ "https://github.com/#{$1}/raw/master" else base_url end end |
.all_template_files_exist? ⇒ Boolean
115 116 117 |
# File 'lib/scaffoldhub/specification.rb', line 115 def all_template_files_exist? files.all? { |file| remote_file_exists?(File.join(adjusted_base_url, file[:src])) } end |
.has_base_url? ⇒ Boolean
100 101 102 |
# File 'lib/scaffoldhub/specification.rb', line 100 def has_base_url? has_string_value?(:base_url) end |
.has_description? ⇒ Boolean
96 97 98 |
# File 'lib/scaffoldhub/specification.rb', line 96 def has_description? has_string_value?(:description) end |
.has_name? ⇒ Boolean
92 93 94 |
# File 'lib/scaffoldhub/specification.rb', line 92 def has_name? has_string_value?(:name) end |
.has_screenshot? ⇒ Boolean
111 112 113 |
# File 'lib/scaffoldhub/specification.rb', line 111 def has_screenshot? has_string_value?(:screenshot) && remote_file_exists?(File.join(adjusted_base_url, screenshot)) end |
.has_string_value?(value) ⇒ Boolean
104 105 106 107 108 109 |
# File 'lib/scaffoldhub/specification.rb', line 104 def has_string_value?(value) val = send(value) valid = (val && val != '') errors.push("Error: missing scaffold #{value}.") unless valid valid end |
.remote_file_exists?(url) ⇒ Boolean
119 120 121 122 123 |
# File 'lib/scaffoldhub/specification.rb', line 119 def remote_file_exists?(url) valid = RemoteFile.new(url).exists? errors.push("Error: unable to access remote URL #{url}") unless valid valid end |
.to_yaml ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scaffoldhub/specification.rb', line 63 def to_yaml { :name => name, :description => description, :base_url => adjusted_base_url, :blog_post => blog_post, :gems => gems, :files => files, :screenshot => screenshot, :tags => , :parameter_example => parameter_example, :post_install_message => }.to_yaml end |
.valid? ⇒ Boolean
88 89 90 |
# File 'lib/scaffoldhub/specification.rb', line 88 def valid? has_name? && has_description? && has_base_url? && has_screenshot? && all_template_files_exist? end |
Instance Method Details
#file(src, options = {}, type = :file) ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/scaffoldhub/specification.rb', line 143 def file(src, = {}, type = :file) self.class.add_file( join_with_parent(@context_options[:src], src), join_with_parent(@context_options[:dest], [:dest]), [:rename], type ) end |
#gem(*args) ⇒ Object
161 162 163 |
# File 'lib/scaffoldhub/specification.rb', line 161 def gem(*args) @@gems << args end |
#metadata ⇒ Object
139 140 141 |
# File 'lib/scaffoldhub/specification.rb', line 139 def yield if block_given? end |
#tag(keyword) ⇒ Object
157 158 159 |
# File 'lib/scaffoldhub/specification.rb', line 157 def tag(keyword) self.class.add_tag(keyword) end |
#template(src, options = {}) ⇒ Object
152 153 154 155 |
# File 'lib/scaffoldhub/specification.rb', line 152 def template(src, = {}) raise ':dest option is required for templates' unless [:dest] file(src, , :template) end |
#with_options(options, &block) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/scaffoldhub/specification.rb', line 132 def (, &block) @context_stack.push(@context_options) @context_options = (@context_options, ) yield if block_given? @context_options = @context_stack.pop end |