Class: Starter::Builder
- Inherits:
-
Object
- Object
- Starter::Builder
- Extended by:
- BaseFile, Names, Templates::Endpoints, Templates::Files
- Defined in:
- lib/starter/builder.rb
Class Attribute Summary collapse
-
.destination ⇒ Object
readonly
Returns the value of attribute destination.
-
.entity ⇒ Object
readonly
Returns the value of attribute entity.
-
.force ⇒ Object
readonly
Returns the value of attribute force.
-
.orm ⇒ Object
readonly
Returns the value of attribute orm.
-
.prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
.resource ⇒ Object
readonly
Returns the value of attribute resource.
-
.set ⇒ Object
readonly
Returns the value of attribute set.
Class Method Summary collapse
-
.add!(resource, options = {}) ⇒ Object
would be called from add command.
- .config_static ⇒ Object
-
.endpoint_specs ⇒ Object
provides the specs for the endpoints of the resource.
-
.endpoints ⇒ Object
provides the endpoints for the given resource.
-
.new!(name, source, destination, options = {}) ⇒ Object
public methods.
-
.remove!(resource, options = {}) ⇒ Object
would be called on from rm command.
Methods included from Names
api_base_file_name, api_file_name, api_spec_name, base_file_name, base_spec_name, entity_file_name, klass_name, lib_file_name, lib_klass_name, lib_spec_name, mount_point
Methods included from BaseFile
add_mount_point, add_to_base, base_file, base_prefix, base_version, remove_from_base, remove_mount_point
Methods included from Templates::Files
api_file, api_spec, entity_file, lib_file, lib_spec
Methods included from Templates::Endpoints
crud, get_all, get_all_spec, post, post_spec, singular_one
Class Attribute Details
.destination ⇒ Object (readonly)
Returns the value of attribute destination.
20 21 22 |
# File 'lib/starter/builder.rb', line 20 def destination @destination end |
.entity ⇒ Object (readonly)
Returns the value of attribute entity.
20 21 22 |
# File 'lib/starter/builder.rb', line 20 def entity @entity end |
.force ⇒ Object (readonly)
Returns the value of attribute force.
20 21 22 |
# File 'lib/starter/builder.rb', line 20 def force @force end |
.orm ⇒ Object (readonly)
Returns the value of attribute orm.
20 21 22 |
# File 'lib/starter/builder.rb', line 20 def orm @orm end |
.prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
20 21 22 |
# File 'lib/starter/builder.rb', line 20 def prefix @prefix end |
.resource ⇒ Object (readonly)
Returns the value of attribute resource.
20 21 22 |
# File 'lib/starter/builder.rb', line 20 def resource @resource end |
.set ⇒ Object (readonly)
Returns the value of attribute set.
20 21 22 |
# File 'lib/starter/builder.rb', line 20 def set @set end |
Class Method Details
.add!(resource, options = {}) ⇒ Object
would be called from add command
resource - A String as name options - A Hash to provide some optional arguments (default: {})
:set – whitespace separated list of http verbs
(default: nil, possible: post get put patch delete)
:force - A Boolean, if given existent files should be overwriten (default: false)
:entity - A Boolean, if given an entity file would be created (default: false)
64 65 66 67 68 69 70 71 72 |
# File 'lib/starter/builder.rb', line 64 def add!(resource, = {}) @resource = resource @set = [:set] @force = [:force] @entity = [:entity] @orm = [:orm] save_resource end |
.config_static ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/starter/builder.rb', line 47 def config_static [ { file: %w[script server], pattern: "API-#{resource}" }, { file: %w[api base.rb], pattern: prefix ? "prefix :#{prefix}" : nil }, { file: %w[spec requests root_spec.rb], pattern: prefix ? "/#{prefix}" : nil }, { file: %w[spec requests documentation_spec.rb], pattern: prefix ? "/#{prefix}" : nil } ] end |
.endpoint_specs ⇒ Object
provides the specs for the endpoints of the resource
100 101 102 |
# File 'lib/starter/builder.rb', line 100 def endpoint_specs content(endpoint_set.map { |x| "#{x}_spec" }).join("\n") end |
.endpoints ⇒ Object
provides the endpoints for the given resource
95 96 97 |
# File 'lib/starter/builder.rb', line 95 def endpoints content(endpoint_set).join("\n\n") end |
.new!(name, source, destination, options = {}) ⇒ Object
public methods
would be called from new command
name - A String as project name source - A String which provides the template path destination - A String which provides the new project path
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/starter/builder.rb', line 30 def new!(name, source, destination, = {}) @resource = name @destination = destination @prefix = [:p] # can be nil FileUtils.copy_entry source, destination config_static.each do |config| replace_static(File.join(config[:file]), config[:pattern]) end Orms.build(destination, [:orm]) if [:orm] Starter::Config.save(dest: destination, content: { prefix: prefix }) self end |
.remove!(resource, options = {}) ⇒ Object
would be called on from rm command
resource - A String, which indicates the resource to remove options - A Hash to provide some optional arguments (default: {})
:entity - A Boolean, if given an entity file would also be removed (default: nil -> false)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/starter/builder.rb', line 79 def remove!(resource, = {}) @resource = resource @entity = [:entity] file_list.map { |x| send("#{x}_name") }.each do |file_to_remove| begin FileUtils.rm file_to_remove rescue StandardError => error $stdout.puts error.to_s end end remove_mount_point end |