Class: Starter::Builder

Inherits:
Object
  • Object
show all
Extended by:
Names, Template::Endpoints, Template::Files
Defined in:
lib/starter/builder.rb

Class Attribute Summary collapse

Class Method Summary collapse

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_spec_name, mount_point

Methods included from Template::Files

api_file, api_spec, entity_file, lib_file, lib_spec

Methods included from Template::Endpoints

crud, get_all, get_all_spec, post, post_spec, singular_one

Class Attribute Details

.destinationObject (readonly)

Returns the value of attribute destination.



15
16
17
# File 'lib/starter/builder.rb', line 15

def destination
  @destination
end

.entityObject (readonly)

Returns the value of attribute entity.



15
16
17
# File 'lib/starter/builder.rb', line 15

def entity
  @entity
end

.forceObject (readonly)

Returns the value of attribute force.



15
16
17
# File 'lib/starter/builder.rb', line 15

def force
  @force
end

.resourceObject (readonly)

Returns the value of attribute resource.



15
16
17
# File 'lib/starter/builder.rb', line 15

def resource
  @resource
end

.setObject (readonly)

Returns the value of attribute set.



15
16
17
# File 'lib/starter/builder.rb', line 15

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)


39
40
41
42
43
44
45
46
# File 'lib/starter/builder.rb', line 39

def add!(resource, options = {})
  @resource = resource
  @set = options[:set]
  @force = options[:force]
  @entity = options[:entity]

  self
end

.endpoint_specsObject

provides the specs for the endpoints of the resource



87
88
89
# File 'lib/starter/builder.rb', line 87

def endpoint_specs
  content(endpoint_set.map { |x| "#{x}_spec" }).join("\n")
end

.endpointsObject

provides the endpoints for the given resource



82
83
84
# File 'lib/starter/builder.rb', line 82

def endpoints
  content(endpoint_set).join("\n\n")
end

.new!(name, source, destination) ⇒ Object

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



22
23
24
25
26
27
28
29
# File 'lib/starter/builder.rb', line 22

def new!(name, source, destination)
  @resource = name
  @destination = destination

  FileUtils.copy_entry source, destination

  replace_static(File.join('script', 'server'))
end

.remove!(resource, options = {}) ⇒ Object

would be called on from 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)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/starter/builder.rb', line 66

def remove!(resource, options = {})
  @resource = resource
  @entity = options[:entity]

  file_list.map { |x| send("#{x}_name") }.each do |file_to_remove|
    begin
      FileUtils.rm file_to_remove
    rescue => error
      $stdout.puts error.to_s
    end
  end

  remove_mount_point
end

.saveObject

… it saves the files



50
51
52
53
54
55
56
57
58
59
# File 'lib/starter/builder.rb', line 50

def save
  created_files = file_list.each_with_object([]) do |new_file, memo|
    memo << send("#{new_file}_name")
    save_file(new_file)
  end

  add_mount_point

  created_files
end