Class: Starter::Build
- Inherits:
-
Object
- Object
- Starter::Build
- Extended by:
- Starter::Builder::Endpoints, Starter::Builder::Files, Shared::BaseFile
- Defined in:
- lib/starter/build.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.
-
.naming ⇒ Object
readonly
Returns the value of attribute naming.
-
.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.
-
.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 Shared::BaseFile
add_mount_point, add_to_base, base_file, base_file_path, base_prefix, base_version, remove_from_base, remove_mount_point
Methods included from Starter::Builder::Files
api_file, api_spec, base_namespace_file, entity_file, lib_file, lib_spec
Methods included from Starter::Builder::Endpoints
crud, get_all, get_all_spec, post, post_spec, singular_one
Class Attribute Details
.destination ⇒ Object (readonly)
Returns the value of attribute destination.
10 11 12 |
# File 'lib/starter/build.rb', line 10 def destination @destination end |
.entity ⇒ Object (readonly)
Returns the value of attribute entity.
10 11 12 |
# File 'lib/starter/build.rb', line 10 def entity @entity end |
.force ⇒ Object (readonly)
Returns the value of attribute force.
10 11 12 |
# File 'lib/starter/build.rb', line 10 def force @force end |
.naming ⇒ Object (readonly)
Returns the value of attribute naming.
10 11 12 |
# File 'lib/starter/build.rb', line 10 def naming @naming end |
.orm ⇒ Object (readonly)
Returns the value of attribute orm.
10 11 12 |
# File 'lib/starter/build.rb', line 10 def orm @orm end |
.prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/starter/build.rb', line 10 def prefix @prefix end |
.resource ⇒ Object (readonly)
Returns the value of attribute resource.
10 11 12 |
# File 'lib/starter/build.rb', line 10 def resource @resource end |
.set ⇒ Object (readonly)
Returns the value of attribute set.
10 11 12 |
# File 'lib/starter/build.rb', line 10 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: {})
:resource - the name of the resource to create
: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)
:orm - A Boolean, if given the created lib/model file will be inherited orm specific (default: false)
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/starter/build.rb', line 61 def add!(resource, = {}) @resource = resource @set = [:set] @force = [:force] @entity = [:entity] @orm = [:orm] @naming = Starter::Names.new(@resource) Orms.add_migration(@naming.klass_name, resource.downcase) if @orm save_resource end |
.endpoint_specs ⇒ Object
provides the specs for the endpoints of the resource
97 98 99 |
# File 'lib/starter/build.rb', line 97 def endpoint_specs content(endpoint_set.map { |x| "#{x}_spec" }).join("\n") end |
.endpoints ⇒ Object
provides the endpoints for the given resource
92 93 94 |
# File 'lib/starter/build.rb', line 92 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,
it will also be the namespace in the lib folder
source - A String which provides the template path destination - A String which provides the new project path options - A Hash to provide some optional arguments (default: {})
:prefix - Sets the Prefix for the API
:orm - Sets and creates ORM specific files
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/starter/build.rb', line 27 def new!(name, source, destination, = {}) @resource = name @destination = destination @prefix = [:p] # can be nil @naming = Starter::Names.new(@resource) FileUtils.copy_entry source, destination config_static.each do |config| replace_static(File.join(config[:file]), config[:pattern]) end add_namespace_with_version Orms.build(name, destination, [:orm]) if [:orm] Starter::Config.save( dest: destination, content: { prefix: prefix, orm: [:orm].to_s } ) 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)
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/starter/build.rb', line 78 def remove!(resource, = {}) @resource = resource @entity = [:entity] file_list.map { |x| send("#{x}_name") }.each do |file_to_remove| FileUtils.rm file_to_remove rescue StandardError => e $stdout.puts e.to_s end remove_mount_point end |