Class: Contentful::Bootstrap::Commands::GenerateJson
- Inherits:
-
Object
- Object
- Contentful::Bootstrap::Commands::GenerateJson
- Defined in:
- lib/contentful/bootstrap/commands/generate_json.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#content_type_ids ⇒ Object
readonly
Returns the value of attribute content_type_ids.
-
#content_types_only ⇒ Object
readonly
Returns the value of attribute content_types_only.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#space_id ⇒ Object
readonly
Returns the value of attribute space_id.
-
#use_preview ⇒ Object
readonly
Returns the value of attribute use_preview.
Instance Method Summary collapse
-
#initialize(space_id, access_token, environment = 'master', filename = nil, content_types_only = false, quiet = false, use_preview = false, content_type_ids = []) ⇒ GenerateJson
constructor
A new instance of GenerateJson.
- #run ⇒ Object
- #write(json) ⇒ Object
Constructor Details
#initialize(space_id, access_token, environment = 'master', filename = nil, content_types_only = false, quiet = false, use_preview = false, content_type_ids = []) ⇒ GenerateJson
Returns a new instance of GenerateJson.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 9 def initialize( space_id, access_token, environment = 'master', filename = nil, content_types_only = false, quiet = false, use_preview = false, content_type_ids = [] ) @space_id = space_id @access_token = access_token @environment = environment @filename = filename @content_types_only = content_types_only @quiet = quiet @use_preview = use_preview @content_type_ids = content_type_ids end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def access_token @access_token end |
#content_type_ids ⇒ Object (readonly)
Returns the value of attribute content_type_ids.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def content_type_ids @content_type_ids end |
#content_types_only ⇒ Object (readonly)
Returns the value of attribute content_types_only.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def content_types_only @content_types_only end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def environment @environment end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def filename @filename end |
#space_id ⇒ Object (readonly)
Returns the value of attribute space_id.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def space_id @space_id end |
#use_preview ⇒ Object (readonly)
Returns the value of attribute use_preview.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def use_preview @use_preview end |
Instance Method Details
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 29 def run if access_token.nil? output 'Access Token not specified' output 'Exiting!' exit(1) end output "Generating JSON Template for Space: '#{space_id}'" output json = Contentful::Bootstrap::Generator.new( space_id, access_token, environment, content_types_only, use_preview, content_type_ids ).generate_json write(json) end |
#write(json) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 51 def write(json) if filename.nil? output "#{json}\n" else output "Saving JSON template to '#{filename}'" ::File.write(filename, json) end end |